+(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;
}
转载于:https://www.cnblogs.com/ningmengcao-ios/p/5825524.html
相关资源:JAVA上百实例源码以及开源项目源代码