name keywords google etiquetas ejemplos ios objective-c json afnetworking content-type

ios - keywords - Cómo configurar el tipo de contenido en AFnetworking



meta tags google (2)

Este código funciona

C objetivo

manager.responseSerializer.acceptableContentTypes=[NSSet setWithObject:@"text/html"];

rápido

manager.responseSerializer.acceptableContentTypes=NSSet (object: "text/html") as Set<NSObject>

Estoy teniendo problemas con AFNetworking. No puedo configurar content-type a application/json . ¿Como lo puedo hacer? Intento muchas soluciones, pero nadie ha funcionado. aquí tienes mi código:

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]; }];

Recibo esta respuesta

{ 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"; Date = "Sun, 20 Jul 2014 22:34:59 GMT"; Server = "nginx/1.2.1"; } }>

ACTUALIZAR:

trato de agregar esto

AFJSONRequestSerializer *requestSerializer = [AFJSONRequestSerializer serializer]; [requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; [requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"]; operationManagerInstance.requestSerializer = requestSerializer;

mi aplicación se bloquea

ACTUALIZACIÓN 2: funciona. quité esta línea

[requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"];


Esto funcionó para mí!

[requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"];