IOS开发之application/x-www-form-urlencoded ;charset=utf-8

本来常用的是application/json的这中格式,做ios常用的网络请求框架AFNetworking,默认也是application/json,前不久就遇到这种接受格式问题,按照网上各种说法,改了AFNetworking的设置,最终还是无法解决问题,最后也放弃了使用AFNetworking。写了个原生的网络请求就解决了问题。

代码如下:

  NSHTTPURLResponse *response = nil;

     NSError *erro = nil;

     NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL:[NSURL URLWithString:urlStr]];

     request.HTTPMethod = @"POST";
//设置格式
[request addValue:@"application/x-www-form-urlencoded ;charset=utf-8" forHTTPHeaderField:@"Content-Type"];
//
[request addValue:@"" forHTTPHeaderField:@"x-wh-token"];
//用HMAC加密
NSString *serkey = [NSString hmacsha1:@"" key:key]; [request addValue:serkey forHTTPHeaderField:@"x-wh-signature"]; [request setHTTPBody:[body dataUsingEncoding:NSUTF8StringEncoding]]; NSData *requesData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&erro];
上一篇:Android Activity的4种启动模式详解(示例)


下一篇:在VMware上安装Ubuntu14.04 , Docker