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

Posts: 64
Registered: ‎02-12-2011
My Device: 9300
My Carrier: Yoigo
Accepted Solution

Sending long HTTP POST with URLEncodedPostData

Hi all.

I'm trying to call a REST service that receives POST String parameters and I did it succesfully with URLEncodedPostData until I needed to send a "long" String param (around 40K. It is a single HTML page). Then, I received a 500 error code from the server. Should I consider an special case after a certain size or could it be a server error?

This is how I build the object URLEncodedPostData

URLEncodedPostData data = new URLEncodedPostData("UTF-8", false);
data.append("email", user.getEmail());
data.append("password", user.getPassword());
data.append("subject", subject);
data.append("content", content);


... then to send the POST

ConnectionFactory conn = new ConnectionFactory(); 
ConnectionDescriptor desc = conn.getConnection(url); 
c = (HttpConnection) desc.getConnection(); 
c.setRequestMethod(HttpConnection.POST); c.setRequestProperty(HttpHeaders.HEADER_CONTENT_TYPE,data.getContentType()); c.setRequestProperty(HttpHeaders.HEADER_CONTENT_LENGTH,String.valueOf(data.getBytes().length)); c.setRequestProperty(HttpHeaders.HEADER_ACCEPT, HttpHeaders.CONTENT_TYPE_APPLICATION_XML); 
OutputStream os = c.openOutputStream(); 
int rc = c.getResponseCode();


So rc is 500 which is bad but if I chop to content to 

data.append("content", content.substring(0,100));


it works fine. That's why I believe it a problem with the POST size.

Any ideas?

Posts: 16,893
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Sending long HTTP POST with URLEncodedPostData

500 is internal server error, so it seems unlikely to be a client problem. in any case, you will have to investigate on the server-side, or find a different way to operate.
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Posts: 64
Registered: ‎02-12-2011
My Device: 9300
My Carrier: Yoigo

Re: Sending long HTTP POST with URLEncodedPostData

Thank you simon_hain.
So I can safely assume that the package is sent with the full content and the server is receiving it but proccessing it wrong.
I'll investigate on the server-side and mark it as solved when I get it work.
Changing subject... Who do I need to write to remove a duplicated post? I posted this twice by mistake.
Cheers and thanks again.
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Sending long HTTP POST with URLEncodedPostData

The first thing you need to do is confirm that in fact the data hit your server.  The 500 response could, especially if the communication was via wireless, be supplied by an intervening gateway.  Don't think it is likely, but I think you should check.  If you check the headers returned on with the 500 response you should see the Server identified and may be able to determine from that it was in fact your server. 


Regarding removing a duplicate post, press the "Report Inappropriate Content" link to the left of the post, and explain your error.  That seems to work for me when I do it.....

Posts: 64
Registered: ‎02-12-2011
My Device: 9300
My Carrier: Yoigo

Re: Sending long HTTP POST with URLEncodedPostData

I just checked and I can confirm that the problem was not on the device but on the server.

The content was sent completely to the right server using the code written before but the server didn't handle because it has size limitations.

Thank you all for your comments. Kudos for you Smiley Happy