码迷,mamicode.com
首页 > 移动开发 > 详细

苹果原生请求封装

时间:2016-08-31 14:04:57      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:

+(NSMutableURLRequest  *)putRequestWithUrl:(NSString *)urlString HTTPMethod:(NSString *)httpMethod HTTPBody:(NSString *)httpBody;


+(NSMutableURLRequest  *)putRequestWithUrl:(NSString *)urlString HTTPMethod:(NSString *)httpMethod HTTPBody:(NSString *)httpBody
{
    //1.创建URL
    NSURL *url = [NSURL URLWithString:urlString];
    
    //2.创建NSURLRequest
    // 注意: 如果需要设置请求体或者其他请求参数, 必须使用NSURLRequest的子类
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    
    //设置模式      // 注意点: 必须大写
    request.HTTPMethod = httpMethod;
    //设置请求体 // 注意: 只要是POST请求, 系统内部会自动添加?
    // post发送中文没有问题
    request.HTTPBody = [httpBody dataUsingEncoding:NSUTF8StringEncoding];
    // 设置超时时间
    request.timeoutInterval = 10;
    [request setValue:@"application/x-www-form-urlencoded"
   forHTTPHeaderField:@"Contsetent-Type"];
    
    return  request;
    
    
}

 

苹果原生请求封装

标签:

原文地址:http://www.cnblogs.com/ningmengcao-ios/p/5825524.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!