小编cro*_*rox的帖子

如何在AFnetworking中设置内容类型

我遇到了AFNetworking的问题.我无法设置content-typeapplication/json.我能怎么做?我尝试了很多解决方案,但没有人工作过.这是你的代码:

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
  if (self.enableBasicAuth){
    [manager setRequestSerializer:[AFHTTPRequestSerializer serializer]];
    [manager.requestSerializer setAuthorizationHeaderFieldWithUsername:[[SOWMerchant merchant]     username] password:[[SOWMerchant merchant] password]];
  }
  [manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
  manager.responseSerializer = [AFJSONResponseSerializer serializer];
  [manager POST:[NSString stringWithFormat:@"%@", url] parameters:postData success:^(AFHTTPRequestOperation *operation, id responseObject) {
    [self onSuccessResponse:responseObject request:operation];
  } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    [self onError:error request:operation];
  }];
Run Code Online (Sandbox Code Playgroud)

我收到了这个回复

{ URL: https://sbengtest.spotonway.com:9099/v1.0/merchant/check }, response: <NSHTTPURLResponse:  0x10aa20530> { URL: https://sbengtest.spotonway.com:9099/v1.0/merchant/check } { status code: 400,     headers {
Connection = "keep-alive";
"Content-Length" = 192;
"Content-Type" = "text/html"; …
Run Code Online (Sandbox Code Playgroud)

json content-type objective-c ios afnetworking

19
推荐指数
2
解决办法
2万
查看次数

标签 统计

afnetworking ×1

content-type ×1

ios ×1

json ×1

objective-c ×1