开发者

How to create HTTP PUT Request on BlackBerry

To give some background: I'm building a BlackBerry frontend to talk to a backend web service built to support only PUT requests for a lot of important resources instead of POST requests.

This backend worked fine for iOS but I can't seem to create a PUT request on the BlackBerry. Looking through the BlackBerry API, I've been able to create GET/POST requests with the following code:

HttpConnection conn = (HttpConnection) Connector.open(URL);  
conn.setRequestMethod(HttpConnection.GET);

or

conn.setRequestMethod(HttpConnection.POST);

It seems that the HttpConnection class should support a PUT command as seen in the API here. I've tried manually setting conn.setRequestMethod("PUT"); but I keep getting a 400 error from the server.

Does anyone know how to properly create a PUT request for the BlackBerry? My search throughout the web hasn't brought back any usable soluti开发者_运维问答ons so far. =( Thanks!


HTTP 400 means "The request could not be understood by the server due to malformed syntax.".

So could you confirm your code works OK if you use conn.setRequestMethod(HttpConnection.POST);?

Here is why I'm asking this: According to RESTful web services pattern the difference should be in that PUT is used to update a resource on server while POST is used to create a resource on server. So if your networking code works OK as a POST, then it confirms your code is basically OK.

Another point is "what framework/technology is used on server side?". This could be important, because browsers do not support PUTs (only GET and POST) natively, so web-apps usually simulate PUTs by putting a hidden form field (smth like "_method=PUT") in web-forms. So when user clicks Submit, then browser does a POST which includes "_method=PUT" param, so the server can recognize it is a PUT. This is used in Rails and I suspect others do some similar stuff. If this is your case, then just try appending your POST params with a required by your web-app param (smth like "_method=PUT").

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜