×

Discussion Board

Results 1 to 3 of 3

Threaded View

  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.

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
  •