AFNetworking怎么post x-www-form-ur

2017-07-04  本文已影响19人  ddffsg

NSMutableURLRequest*request = [NSMutableURLRequestrequestWithURL:[NSURLURLWithString:url]];

[request setTimeoutInterval:ACTION_TIMEOUT];

[request setHTTPMethod:@"POST"];

[request setValue:@"application/x-www-form-urlencoded"forHTTPHeaderField:@"Content-Type"];

request.HTTPBody=@"key1=value1&key2=value2....";

AFHTTPRequestOperation* operation = [[AFHTTPRequestOperation alloc] initWithRequest:_request];

[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation,idresponseObject) {

NSLog(@"operation hasAcceptableStatusCode: %d", [operation.response statusCode]);

} failure:^(AFHTTPRequestOperation *operation,NSError*error) {

if(error.code !=NSURLErrorTimedOut) {

NSLog(@"error: %@", error);

}

}];

[operation start];

HTTPBody需要从NSString转NSData

上一篇 下一篇

猜你喜欢

热点阅读