-(NSString *)GetReturnFromPost:(NSString*)urlStr postData:(NSString*)_postData
{
NSData *postData = [_postData dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:urlStr]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
//[NSURLConnection connectionWithRequest:request delegate:self ];
//同步请求的的代码
//returnData就是返回得到的数据
NSData *returnData =[NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
return [[NSString alloc]initWithData:returnData encoding:NSUTF8StringEncoding];
}
转载于:https://www.cnblogs.com/zzzili/p/6662540.html