my code is as follows
there is no response from serverCode:public String sentPostCommentToServer(String uploadURL, String data) { System.out.println("contact upload url " + uploadURL); System.out.println("contact upload data " + data); //Log.setLogLevel(Log.INFO); //Log.info(LOG_TAG, "url to hit=" + uploadURL); // Log.info(LOG_TAG, "data to post=" + data); HttpConnection hc = null; InputStream is = null; StringBuffer stb = new StringBuffer(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { hc = (HttpConnection) Connector.open(uploadURL); hc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=utf-8"); hc.setRequestProperty("User-Agent", "Profile/MIDP-1.0 Confirguration/CLDC-1.0"); hc.setRequestProperty("Content-Language", "en-US"); hc.setRequestProperty("Content-Length", "" + data.length()); hc.setRequestMethod(HttpConnection.POST); OutputStream dout = hc.openOutputStream(); byte[] Data = data.getBytes(); System.gc(); dout.write(Data); dout.flush(); //dout.close(); System.out.println("after flush"); //System.out.println("value of getresponse code"+hc.getResponseCode()); int ch; is = hc.openInputStream(); System.out.println("after openInputstream"); long len = hc.getLength(); System.out.println("content length = " + len); if (len != -1) { // Read exactly Content-Length bytes for (int i = 0; i < len; i++) if ((ch = is.read()) != -1) { stb.append((char) ch); } } else { // Read until the connection is closed. while ((ch = is.read()) != -1) { len = is.available(); stb.append((char) ch); } } System.out.println(stb.toString()); if (hc.getResponseCode() == 200) { System.out.println("value of getresponse code"+hc.getResponseCode()); } if (hc.getResponseCode() != 200) { } String temp = stb.toString(); if (temp.length() == 0) { temp = "zero length"; } // Log.setLogLevel(Log.INFO); //Log.info(LOG_TAG, "responce of this post=" + stb.toString()); return stb.toString(); } catch (ConnectionNotFoundException cnfe) { cnfe.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } finally { // close all the connections. try { if (bos != null) bos.close(); if (is != null) is.close(); if (hc != null) hc.close(); } catch (Exception e2) { e2.printStackTrace(); } } return "Connection Not Found"; }

Reply With Quote

