美文网首页
NSMutableURLRequest post json

NSMutableURLRequest post json

作者: daomangquan | 来源:发表于2016-08-17 17:43 被阅读0次

NSString *urlstr = [NSString stringWithFormat:@"%@%@",BASE_API_URL,rqSaveAll];

NSURL *url = [NSURL URLWithString:urlstr];

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10];

[request setHTTPMethod:@"POST"];

NSString *str = [CommonUtil toJSONData:arr];

NSData *data = [str dataUsingEncoding:NSUTF8StringEncoding];

[request setHTTPBody:data];

[request addValue:@"application/json; charset=utf-8" forHTTPHeaderField:@"Content-Type"];

NSData *pData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];

NSString *receive = [[NSString alloc] initWithData:pData encoding:NSUTF8StringEncoding];

NSLog(@"receive-------%@",receive);

相关文章

网友评论

      本文标题:NSMutableURLRequest post json

      本文链接:https://www.haomeiwen.com/subject/ytgmsttx.html