如何使用 AFNetworking 将简单字符串(无 JSON 或任何其他格式)添加到发布请求?
我已经成功的最好的方法是用“=”连接。
和这个:
NSURLRequest* request =[myServer multipartFormRequestWithMethod:@"POST" path:@"http://my.server.com" parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
NSData *tmp_data = [NSString stringWithFormat:@"%@", @"my_string!"];
[formData appendPartWithHeaders:nil body:tmp_data];
}];
提前致谢!
很简单,这应该是答案:
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:@"http://www.my.server.com"]];
[request setHTTPMethod:@"POST"];
//set headers
NSString *contentType = @"text/xml";
[request addValue:contentType forHTTPHeaderField: @"Content-Type"];
[request addValue:@"any-value" forHTTPHeaderField: @"User-Agent"];
//create the body
NSMutableData *postBody = [NSMutableData data];
[postBody appendData:[@"my_body_string!" dataUsingEncoding:NSUTF8StringEncoding]];
//post
[request setHTTPBody:postBody];
从这里开始,用 http 做你想做的事request
(我使用 AFNetworking 进行发送)。
Cheers!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)