Sunday, 15 August 2010

blackberry - How do we pass parameters when doing HTTP Post? -


I am working on an app where giving us specific web API parameters for the web app using HTTP web pages. Will happen. Ex: apimethod name parameter 1 value parameter 2 value, then do I use string or url encoded postdata to send that data? It would be nice if u help me with a code. I'm using something like this but it does not post data on the server. Although the response code is OK / 200 and when I read the httpresponse input stream, I get a parsed HTML response. But the code does not post anything. Therefore, unable to receive expected response.

  _postData.append ("method", "session.getToken"); _postData.append ("Developer", "Value"); _postData.append ("clientID", "value"); _httpConnection = (HTTP Connection) Connector.Open (URL, Connector. RAD_Virate); String encoded data = _postData.toString (); _httpConnection.setRequestMethod (HttpConnection.POST); _httpConnection.setRequestProperty ("User-agent", "Blackberry / 3.2.1"); _httpConnection.setRequestProperty ("content-language", "N-US"); _httpConnection.setRequestProperty ("content type", "application / x-www form-urlencoded"); _httpConnection.setRequestProperty ("content-length", (new integer (encoded data .line ()). ToString ()); OS = _httpConnection.openOutputStream (); Oswrite (requeststring.getBytes ()); `   

The code posted to you looks correct - though you do more things (You may have done this before but did not include it in your code):

  1. Once you have closed the outstream in everything you wrote
  2. Call getResponseCode () so that it actually sends the request

No comments:

Post a Comment