Objective C - 使用NSURLConnection发布POST数据 [英] Objective C - POST data using NSURLConnection
问题描述
我正在慢慢地学习用于iOS开发的URL加载系统,我希望有人可以简要解释下面这段代码:
I'm very slowly working my way through learning the URL loading system for iOS development, and I am hoping someone could briefly explain the following piece of code:
NSString *myParameters = [[NSString alloc] initWithFormat:@"one=two&three=four"];
[myRequest setHTTPMethod:@"POST"];
[myRequest setHTTPBody:[myParameters dataUsingEncoding:NSUTF8StringEncoding]];
最后我希望能够创建一个登录我ISP网站的应用程序并检索多少我已经离开了这个月余下的数据,我觉得我应该首先考虑setHTTPMethod / setHTTPBody。
Eventually I would like to be able to create an application that logs into my ISP's website and retrieves how much data I have left for the rest of the month, and I feel as though I should get my head around setHTTPMethod/setHTTPBody first.
亲切的问候
推荐答案
这是一个非常简单的HTTP请求设置;如果您有更具体的问题,可以更好地询问这些问题。
This is a pretty simple HTTP request setup; if you have more specific questions you might do better asking those.
NSString *myParameters = @"paramOne=valueOne¶mTwo=valueTwo";
这会设置一个包含POST参数的字符串。
This sets up a string containing the POST parameters.
[myRequest setHTTPMethod:@"POST"];
请求必须是 POST请求。
[myRequest setHTTPBody:[myParameters dataUsingEncoding:NSUTF8StringEncoding]];
这会将参数放入帖子正文中(它们需要是原始数据,所以我们先对它们进行编码如UTF-8)。
This puts the parameters into the post body (they need to be raw data, so we first encode them as UTF-8).
这篇关于Objective C - 使用NSURLConnection发布POST数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!