简体   繁体   English

iPhone SDK-检索数据时可以使用HTTP POST吗?

[英]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? 使用iPhone SDK中的NSMutableURLRequest对象,从服务器检索数据时可以将HTTPMethod设置为POST吗?

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. 通常,您应该发布一些数据或获取一些数据,尽管发出POST然后在单个请求中获取一些数据是完全有效的。

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. 需要明确的是,实际上POST响应于POST返回一些表示某种结果消息的数据是很普遍的。 Other uses (like piggy-backing an unrelated GET onto the POST) would be frowned upon. 其他用途(例如将不相关的GET piggy带到POST上)将被反对。

If you are wanting to be HTTP / web standards compliant, you should use a GET when retrieving data. 如果要符合HTTP / Web标准,则在检索数据时应使用GET。 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. 它还取决于您正在与服务器通信的应用程序是否响应给定资源的POST请求。

If you're willing to use third party libraries I can highly recommend ASIHTTPRequest: 如果您愿意使用第三方库,我强烈建议您使用ASIHTTPRequest:

http://allseeing-i.com/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. 我在许多iPhone应用程序的http帖子库中都使用了此工具,对此感到非常满意。

Just to clarify: I'm not associated with these guys in any way, just like the library! 只是要澄清一下:我与图书馆没有任何关系,就像图书馆一样!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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