-(void)PostStr
{
NSString *urlstring= @"http://116.255.130.35:11011/api/TestApi2/PostFromPosData";
NSString *poststr=@"hellowrold";
NSURL *url=[NSURL URLWithString:urlstring];
NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:url];
[request addValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:[poststr dataUsingEncoding:NSUTF8StringEncoding]];
NSOperationQueue *queue=[[NSOperationQueue alloc] init];
[NSURLConnection sendAsynchronousRequest:request queue:queue
completionHandler:^(NSURLResponse *respone,
NSData *data,
NSError *error)
{
if ([data length]>0 && error==nil) {
NSString *jsonstring=[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(jsonstring);
}
}
];
}
NSMutableURLRequest实现Post访问
最新推荐文章于 2016-01-02 15:00:01 发布