HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – 如何使用AFNetwork的AFHTTPRequestOperationManager设置HTTP请求体?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用AFhttprequestOperationManager(2.0 AFNetworking库)进行REST POST请求。但是经理只有打电话来设置参数。

-((AFhttprequestOperation *)POST:(NSString *)URLString
                  parameters:(NSDictionary *)parameters
                     success:(void (^)(AFhttprequestOperation *operation,id responSEObject))success
                     failure:(void (^)(AFhttprequestOperation *operation,NSError *error))failure;

我还需要设置@L_489_1@字符串的http请求体。如何使用AFhttprequestOperationManager?谢谢。

解决方法

我有同样的问题,通过添加如下所示的代码解决它:

NSMutableURLrequest *request = [NSMutableURLrequest requestWithURL:URL
              cachePolicy:NSURLrequestReloadIgnoringCacheData  timeoutInterval:10];

[request sethttpR_665_11845@ethod:@"POST"];
[request SETVALue:@"Basic: someValue" forhttpHeaderField:@"Authorization"];
[request SETVALue: @"application/json" forhttpHeaderField:@"Content-Type"];
[request sethttpBody: [body dataUsingEncoding:NSUTF8StringEncoding]];

AFhttprequestOperation *op = [[AFhttprequestOperation alloc] initWithrequest:request];
op.responseserializer = [AFJSONResponseserializer serializer];
[op setCompletionBlockWithsuccess:^(AFhttprequestOperation *operation,id responSEObject) {

    NSLog(@"JSON responSEObject: %@ ",responSEObject);

} failure:^(AFhttprequestOperation *operation,NSError *error) {
    NSLog(@"Error: %@",[error localizedDescription]);

}];
[op start];

大佬总结

以上是大佬教程为你收集整理的ios – 如何使用AFNetwork的AFHTTPRequestOperationManager设置HTTP请求体?全部内容,希望文章能够帮你解决ios – 如何使用AFNetwork的AFHTTPRequestOperationManager设置HTTP请求体?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。