NSMutableURLRequest post json

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)