简体   繁体   中英

iPhone SDK - Can I use a HTTP POST When retrieving data?

I have a general question. Using the NSMutableURLRequest object in the iPhone SDK, can I set the HTTPMethod to POST when retrieving data from a server?

Normally you should either POST some data or GET some data, though issuing a POST and then fetching some data in a single request is perfectly valid.

Just to be clear, it is in fact quite common for a POST to return some data representing some sort of result message in response to the POST. Other uses (like piggy-backing an unrelated GET onto the POST) would be frowned upon.

If you are wanting to be HTTP / web standards compliant, you should use a GET when retrieving data. It will also depend on if the application you are talking to on the server will respond to a POST request for the given resource.

If you're willing to use third party libraries I can highly recommend ASIHTTPRequest:

http://allseeing-i.com/ASIHTTPRequest/

I've used this in library for http posts in a number of iPhone applications and been very happy with it.

Just to clarify: I'm not associated with these guys in any way, just like the library!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM