Welcome to the Official BlackBerry® Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
New Developer
javaone
Posts: 11
Registered: 07-14-2008

http POST problems

I have been encountering different behavior for the phone networks when using the   the POST method on and http connection. Some networks work flawlessly, other networks seem to kill the connection after 1200 bytes have been transferred.

Has anyone encountered this anomaly ?

Is there a work around ??

Please use plain text.
Developer
RexDoug
Posts: 4,649
Registered: 07-21-2008

Re: http POST problems

I've never seen this. What carrier, what type of connection are you using?
Please use plain text.
New Developer
javaone
Posts: 11
Registered: 07-14-2008

Re: http POST problems

The provider is Nextel

connection is typical 

//==============

                  hc = (HttpConnection) Connector.open("http://urlString", Connector.READ_WRITE, true);
                  // Set the request method and headers
                  hc.setRequestMethod(HttpConnection.POST);
                  hc.setRequestProperty("Content-Language", "en-US");
                  hc.setRequestProperty("Content-Length", Integer.toString(postString.length()));
                  hc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

 

                  dos = new DataOutputStream(hc.openOutputStream());
                 
                  byte outByte[] = PostString.getBytes();
                  dos.write(outByte,0, PostString.length());

 

                  int rc = hc.getResponseCode();
//================

The PostString is encoded via URLEncodedPostData.

I have snt the data via several networks, Sprint, Verizon and ATT. Only  Nextel causes a problem. I worte a java SE app and ran the same data via POST from a SE Java app and had no issues.

 I tried using flush() but the API docs say that getResponseCode flush the output so that has had no effect. The connection seems to break when the data length reaches 1208 bytes. I tried breaking the data into chunks thinking it might be a packet size. That had no effect. Is there any way to control the connection timeout other than the boolean timeout exception flag in the inital connection. This did not help.

 

I have been deploying apps on Blackberry's for 5 years and phones for 10 years. This is really odd

 

Please use plain text.
Developer
Ted_Hopp
Posts: 1,287
Registered: 01-21-2009

Re: http POST problems

Try setting the user agent for the request. I don't know about Nextel, but I've seen weird behavior on some carriers for http requests with no user agent header.

 

Also, do you know if the failure depends only on the data length, or might it also depend on the data content?

 

As an aside: to write bytes, you don't need a DataOutputStream; you can directly use the OutputStream returned by hc.openOutputStream(). If you need a DataOutputStream for some other reason, it's better to call hc.openDataOutputStream() rather than wrapping hc.openOutputStream in your own code. The way you are doing it, the connection won't flush the correct stream. I think DataOutputStream just passes byte array writes directly to the underlying OutputStream, but if it did buffer the data, the code as written has a good chance of failing for that reason.

 

 




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
Please use plain text.
New Developer
javaone
Posts: 11
Registered: 07-14-2008

Re: http POST problems

It appears to be only length. The content is encoded as URLEncodedPostData. I have bb's running on several networks only iDen (Nextel) is a problem. I had seen in Forums that the httpConnection.getResponseCode() flushed the connection and that the connection should only be flushed once. I initially used OutputStream. I'll give that another look.

The odd thing is this is only a problem on iDen.

I have not found any info on other conneciton settings for iDen other than it does not use APN's in the connection string.

I also noticed that if I added ";deviceside=true " to the connection string I got an "invalid url" response

Please use plain text.