Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何制作非键值格式的NSMutableURLRequest标头_Ios_Nsmutableurlrequest - Fatal编程技术网

Ios 如何制作非键值格式的NSMutableURLRequest标头

Ios 如何制作非键值格式的NSMutableURLRequest标头,ios,nsmutableurlrequest,Ios,Nsmutableurlrequest,我需要一个NSMutableURLRequest头,它看起来像: ---开始 POST/index.php HTTP/1.1 内容长度:91 主持人:192.168.1.3:8803 内容类型:application/x-www-form-urlencoded 命令=01&version=V0.1&type=3 ----结束 请告诉我如何使标题字段看起来像最后一行。用空行与其他行分开更好。最后一行不是标题,而是请求的主体。只需将具有该值的主体数据设置为字符串,如下所示: NSString *pa

我需要一个NSMutableURLRequest头,它看起来像:
---开始
POST/index.php HTTP/1.1
内容长度:91
主持人:192.168.1.3:8803
内容类型:application/x-www-form-urlencoded

命令=01&version=V0.1&type=3
----结束

请告诉我如何使标题字段看起来像最后一行。用空行与其他行分开更好。

最后一行不是标题,而是请求的主体。只需将具有该值的主体数据设置为字符串,如下所示:

NSString *params = @"command=01&version=V0.1&type=3";
NSData *data = [params dataUsingEncoding:NSUTF8StringEncoding];

//set headers
[self addValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[self addValue:[NSString stringWithFormat:@"%i", [data length]] forHTTPHeaderField:@"Content-Length"];

//set body
[self setHTTPBody:data];

最后一行不是标题,而是请求的主体。只需将具有该值的主体数据设置为字符串,如下所示:

NSString *params = @"command=01&version=V0.1&type=3";
NSData *data = [params dataUsingEncoding:NSUTF8StringEncoding];

//set headers
[self addValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[self addValue:[NSString stringWithFormat:@"%i", [data length]] forHTTPHeaderField:@"Content-Length"];

//set body
[self setHTTPBody:data];