×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    11

    problem in http post request

    my code is as follows
    Code:
     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";
    	 }
    there is no response from server
    Last edited by sandeepintg; 2012-10-30 at 10:11.

  2. #2
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,073

    Re: problem in http post request

    Is the server up & running - are you able to reach it directly from browser?

    In the flow of above code-- till where you are able to reach -- what the values printed by SOP's --- System.out.println()'s?
    thanks,
    ~Amitabh
    (Champion of the Month -Aug'13)
    Follow me on my blog for Innovative Mobile Apps

  3. #3
    Nokia Developer Champion
    Join Date
    Mar 2003
    Posts
    4,105

    Re: problem in http post request

    sandeepintg, where you able to resolve your issue? Did you try to run this from within one of the Series 40 Platform SDKs? With those, you are able to run several diagnosis windows for network traffic. You can also use Wireshark, to make absolutely sure. If this happens only on a real device, using a WLAN enabled Series 40 helped me a lot to understand the various bugs (mine and Nokia’s). With WLAN, you can capture the traffic (either by placing a protocol sniffer on the Ethernet behind the WLAN access point or by doing a air sniff).

Similar Threads

  1. HTTP POST request on Nokia N9
    By meandnano in forum Nokia N9
    Replies: 1
    Last Post: 2011-09-28, 16:44
  2. Http Post request response
    By anoopd in forum Symbian Networking & Messaging (Closed)
    Replies: 5
    Last Post: 2010-02-27, 14:12
  3. HTTP Post request structure
    By alav in forum Symbian Networking & Messaging (Closed)
    Replies: 7
    Last Post: 2008-08-12, 10:49
  4. KErrCorrupt in a HTTP Post request
    By deepka in forum Symbian Networking & Messaging (Closed)
    Replies: 3
    Last Post: 2008-06-24, 14:06

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •