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. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
Developer
shreyasb
Posts: 152
Registered: ‎07-17-2009
Accepted Solution

java.io.IOException: null for setRequestMethod("POST") of HttpConnection

Hi,

 

I m opening HttpConnection with 

 

 

HttpConnection connection = null; try { connection = (HttpConnection)Connector.open(targetURL); int status = connection.getResponseCode(); System.out.println("status is : " + status); if (status == HttpConnection.HTTP_OK) { System.out.println("HttpConnection.HTTP_OK : "+connection.getResponseMessage()); connection.setRequestMethod("POST"); //connection.setRequestMethod(HttpConnection.POST); System.out.println("connection.setRequestMethod(POST); /*connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); connection.setRequestProperty("Content-Language", "en-US"); //Send request wr = new DataOutputStream(connection.openOutputStream()); wr.writeChars(sendRequest); wr.flush(); wr.close } } catch (IOException e) { System.err.println("ERROR =====> " + e.toString()+":: "+e.getMessage()); e.printStackTrace(); }

 

 But I m getting

java.io.IOException: null for setRequestMethod("POST")

 

Till that executes fine.

 

What is the problem in my code?

 

Please use plain text.
Developer
davidmccormack
Posts: 168
Registered: ‎11-01-2008
My Carrier: Meteor (Ireland)

Re: java.io.IOException: null for setRequestMethod("POST") of HttpConnection

You're doing it in the wrong sequence. You have to do the setRequestMethod(), setRequestProperty() and openOutputStream() before you invoke getResponseCode().
Please use plain text.
Developer
shreyasb
Posts: 152
Registered: ‎07-17-2009

Re: java.io.IOException: null for setRequestMethod("POST") of HttpConnection

Ok. Thanks

 

I will try like that & let u know.

Please use plain text.
Developer
johnbibs
Posts: 903
Registered: ‎02-07-2009
My Carrier: Globe Telecom

Re: java.io.IOException: null for setRequestMethod("POST") of HttpConnection

you already invoked the getResponseMessage()/getResponseCode().  
Please use plain text.
Developer
shreyasb
Posts: 152
Registered: ‎07-17-2009

Re: java.io.IOException: null for setRequestMethod("POST") of HttpConnection

Hey Thanks,

 

Its working now..

 

Thanks a lot for the suggestion..

Please use plain text.