Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
damoncher
Posts: 6
Registered: ‎03-18-2009
My Device: Not Specified

http post size restrictions?

[ Edited ]

Hi!

 

I'm trying to send HTTP POST request on a simulator using JDE 4.6.0.

When data length is less then 6200 bytes everything works fine but when i try to send 6300 bytes simulator throws timeout exception after 2 minutes waiting.

 

Does anyone know why this is happening?

 

Sample code:

 

import javax.microedition.io.Connector;

import javax.microedition.io.HttpConnection;

import java.io.ByteArrayOutputStream;

import java.io.InputStream;

import java.io.OutputStream;

import java.io.IOException;

 

public class HTTP {

 public static void testPost() {

  String url = "http://some_test_url";

  StringBuffer sb = new StringBuffer(6300);

  for (int i = 0; i < 6300; i++) {

   sb.append('A');

  }

  try {

   String result = post(url, sb.toString().getBytes());

  }

  catch (Exception e) {

  }

 }

 

 public static String post(String url, byte[] data) throws Exception {

  try {

   InputStream is;

   HttpConnection http = (HttpConnection) Connector.open(url, Connector.READ_WRITE, true);

   http.setRequestMethod(HttpConnection.POST);

   http.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

   http.setRequestProperty("Content-length", "" + data.length);

   OutputStream out = http.openOutputStream();

   out.write(data);

   out.flush();

   String response = null;

   byte[] buff;

   int rc = http.getResponseCode();

   if (rc == HttpConnection.HTTP_OK) {

    int len = (int) http.getLength();

    is = http.openInputStream();

    if (len != -1) {

     buff = new byte[len];

     is.read(buff);

    }

    else {

     ByteArrayOutputStream baos = new ByteArrayOutputStream();

     int ch;

     while ((ch = is.read()) != -1) {

      baos.write(ch);

     }

     buff = baos.toByteArray();

     baos.close();

    }

    response = new String(buff);

   }

   else {

    throw new IOException("HTTP response code: " + rc);

   }

   http.close();

   return response;

  }

  catch (Exception e) {

   throw new Exception("Can't send http post request" );

  }

 }

}

 

 

 

 

 

Message Edited by damoncher on 03-18-2009 09:29 PM
Please use plain text.
New Developer
damoncher
Posts: 6
Registered: ‎03-18-2009
My Device: Not Specified

Re: http post size restrictions?

I researched the issue further and discovered that there is no such problem with JDE 4.7.0.

I assume the cause is in MDS-CS Simulator which I use to simulate internet connection.

So the question how to resolve this iin JDE 4.6.0 is still open and any help is welcome.

Please use plain text.
New Developer
wxsouth
Posts: 4
Registered: ‎08-12-2009
My Device: Not Specified

Re: http post size restrictions?

Did you ever get this resolved with 4.6.0?  I'm having the same issue.  Also, does the problem translate to the actual devices, or does it just affect the phone/mds simulator?

 

Thanks,

Parks

Please use plain text.
New Developer
damoncher
Posts: 6
Registered: ‎03-18-2009
My Device: Not Specified

Re: http post size restrictions?

No, unfortunately I didn't resolved this issue with 4.6.0 SDK. As workaround, I tested my application with 4.7.2 where it works fine. Also, there are no problems appear on actual devices.
Please use plain text.
Visitor
jitainasknow
Posts: 1
Registered: ‎05-13-2010
My Device: 9000
My Carrier: Airtel

Re: http post size restrictions?

OutputStream out = http.openOutputStream();

after flush just close it

out.flush();

out.close();

 

Please use plain text.