NSMutableURLRequest实现Post访问

简介: NSMutableURLRequest实现Post访问
-(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);
         }
     }
     ];
}
相关文章
|
25天前
|
网络协议 数据安全/隐私保护
get和post的区别
get和post的区别
19 0
|
5月前
post 的接口请求
post 的接口请求
34 0
|
8天前
|
Web App开发 缓存 网络协议
get和post的区别!
get和post的区别!
|
19天前
|
存储 缓存 JSON
|
8月前
|
缓存
get和post的区别
`GET` 和 `POST` 是 HTTP 请求方法,常用于客户端(如浏览器)与服务器之间的通信。
|
4月前
|
缓存 安全 数据安全/隐私保护
GET和POST有什么区别
GET和POST有什么区别
|
10月前
|
网络协议 安全 数据安全/隐私保护
GET与POST的区别
GET与POST的区别
97 0
|
10月前
|
Web App开发 网络协议 安全
GET和POST两种基本请求方法的区别
GET和POST两种基本请求方法的区别
|
网络协议 安全
GET 和 POST 的区别
GET 和 POST 的区别
104 0