我需要用nsmutableurlrequest和nsmutableurlconnection向服务器发送请求,而不使用http头。我找到这个来删除头[request setValue:@"" forHTTPHeaderField:@"User-Agent"];的内容,但我需要删除所有头。
现在:

GET / HTTP/1.1
Host: 127.0.0.1:5555
Accept: */*
Accept-Language: en-us
Connection: keep-alive
Accept-Encoding: gzip, deflate
User-Agent:

需要:
Custom text like "Hello"

代码:
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];

最佳答案

我真的不知道为什么要删除头,因为可能有一些默认的头字段。但我想你可以用这个

NSURLConnection *connection;
NSURL* url=[NSURL URLWithString:@"your url"];

NSMutableURLRequest *request = [NSMutableURLRequest
requestWithURL:[url standardizedURL]];

//set http method GET OR POST OR WHATEVER
[request setHTTPMethod:@"GET"];
 connection=[NSURLConnection connectionWithRequest:request delegate:self];

我认为它会起作用,头将作为空值发送

关于objective-c - 删除NSMutableURLRequest中的HTTP header ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28380874/

10-11 20:36