2
我試圖將一些NSURLConnection代碼轉換爲AFNetworking 2.0,我遇到POST調用的問題。 GET調用工作,但不是POST。AFNetworking 2.0標頭內容類型沒有在POST調用發送
這裏是我的代碼:
+(void)login:(User*)myUser
{
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
[manager.requestSerializer setAuthorizationHeaderFieldWithUsername:myUser.username password:myUser.password];
[manager.requestSerializer setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[manager POST:URL_LOGIN
parameters:nil
success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"success! Response = %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"failure. Error = %@", error);
}];
}
而這裏的錯誤我取回從服務器:
Error Domain=com.<server>.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: text/html" UserInfo=0x7fe043c43670 {com.<server>.serialization.response.error.response=<NSHTTPURLResponse: 0x7fe043d52850> { URL: http://<server>/login.htm;jsessionid=98399EA8F090BF310D1CF5FD3C992A21?login_error=1 } { status code: 200, headers {
"Content-Language" = en;
"Content-Length" = 2801;
"Content-Type" = "text/html;charset=ISO-8859-1";
Date = "Tue, 28 Apr 2015 15:30:21 GMT";
Server = "Apache-Coyote/1.1";
我也試圖明確將在Content-Type作爲PARAM但它是不工作。
我發現很多網上的建議說要麼修改服務器(我不能),要麼只是設置manager.requestSerializer = [AFJSONRequestSerializer serializer];
這顯然不工作。
對此的任何建議將不勝感激。此外,如前所述,與此Content-Type的此通信在NSURLConnection和NSMutableURLRequest之間起作用。
謝謝!
感謝。我得到它與「manager.responseSerializer = [AFHTTPResponseSerializer序列化程序];」序列化器並移除調用以請求特定的內容類型。 – TooManyEduardos