设置请求标头

时间:2016-12-21 05:29:33

标签: ios nsurlsession nsurlrequest

我发送的请求标题为。

  NSDictionary *headers = @{ @"content-type": @"application/x-www-form-urlencoded",
                               @"Connection":@"keep-alive",
                               @"cache-control": @"no-cache",
                               @"postman-token": @"eb834958-a82f-3fd8-0b64-e007df45835c" };

    NSMutableData *postData = [[NSMutableData alloc] initWithData:[@""   dataUsingEncoding:NSUTF8StringEncoding]];
    NSString *logString=[NSString stringWithFormat:@"Here the Url is : \n\n\n\n %@ \n\n\n\n\nAction Used is :========>  %@ \n\n\n\n\n and the Parmeter posted are :=============> %@",IOS_BASE_URL,action,parmetersToPost];
    NSLog(@"%@",logString);
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url                                                           cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                       timeoutInterval:20.0];
    [request setHTTPMethod:@"POST"];
    [request setAllHTTPHeaderFields:headers];
    [request setHTTPBody:postData];
    NSLog(@"All header Sent are %@", request.allHTTPHeaderFields);
   [[[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:ourBlock] resume];

以下是

的控制台日志
  

NSLog(@“所有标题已发送为%@”,request.allHTTPHeaderFields);

All header Sent are {
    "Cache-Control" = "no-cache";
    Connection = "keep-alive";
    "Content-Type" = "application/x-www-form-urlencoded";
    "postman-token" = "eb834958-a82f-3fd8-0b64-e007df45835c";
}
2016-12-21 10:36:07.091 MyAPP[7521:1256842] Here the Url With action is : 



  https://www.xyzz.com/app/xyz/dummy.php 




 and the Parmeter posted are :=============>
 &platform=ios&app_type=MyAPP&app_flag=18&version=1.3&account_type=1&user_type=1&device_id=xx
2016-12-21 10:36:08.324 MyAPP[7521:1256842] Response is <pre>Array
(
    [User-Agent] => MyAPP/1 CFNetwork/758.5.3 Darwin/15.6.0
    [Accept-Encoding] => gzip, deflate
    [Cache-Control] => no-cache
    [Accept-Language] => en-us
    [Connection] => close
    [Content-Length] => 151
    [Accept] => */*
    [Content-Type] => application/x-www-form-urlencoded
    [Postman-Token] => eb834958-a82f-3fd8-0b64-e007df45835c
    [Host] => www.xyz.com
)

我正在发送Connection =“keep-alive”;但我收到的标题收到的响应是打印得很近。

如何解决这个问题。任何帮助都是非常明确的

0 个答案:

没有答案