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
Regular Contributor
erAjayGoyal
Posts: 97
Registered: ‎04-19-2012
My Device: BB Torch-9800
My Carrier: *

How to pass data in the body of HttpConnection in blackberry?

Actually I want to pass text data in the body of httpconnection.

I was trying with apache httpclient library in blackberry, have been integrated jar file in my project but getting compilation error while running my project. 

Kindly tell me how to pass a body in HttpConnection using 'POST' method.

Below code i am using but getting null data in response:

byte [] bodyBytes = getBodyBytesFromSomewhere();
OutputStream out = httpConnection.openOutputStream();
out.write(bodyBytes);
out.flush();
out.close();

 

Please use plain text.
Developer
peter_strange
Posts: 19,603
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to pass data in the body of HttpConnection in blackberry?

Remember that you can't used J2SE code in a J2ME application.  I suspect that is why you are not able to use the Apache code.

 

With respect to why your post code is not working, there are a lot of possible reasons, too many so that all we would be doing is speculating.  Please try out you code carefully and make sure you are setting the write connection method and that you are setting the correct headers, for example the header length, which you don't set is probably required.  I recommend that you search the forum for the many many links on networking - it is not easy for BB.  There is a lot to learn,  Start by just typing network in the search box and look t the videos that you find...

Please use plain text.
Developer
peter_strange
Posts: 19,603
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to pass data in the body of HttpConnection in blackberry?

Please use plain text.