AFNetwirking的post請求返回錯誤!如代碼 ?

   AFHTTPRequestOperationManager * manager = [AFHTTPRequestOperationManager manager];
//    manager.responseSerializer = [AFJSONResponseSerializer serializer];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    manager.responseSerializer.acceptableContentTypes = [manager.responseSerializer.acceptableContentTypes setByAddingObject: @"text/plain"];
    [manager POST:@"http://wu.itmingong.org:9090/WuNetbars/app/login.do"parameters:parameters success:^(AFHTTPRequestOperation *operation,idresponseObject) {
//        NSDictionary * dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"success");
    } failure:^(AFHTTPRequestOperation *operation,NSError*error) {
        NSLog(@"錯誤,%@", error);
    }];


錯誤信息
Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: bad request (400)" UserInfo=0x7fbf4947edf0 {com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x7fbf49484230> { URL: http://wu.itmingong.org:9090/WuNetbars/app/login.do  } { status code: 400, headers {
    Connection = close;
    "Content-Language" = en;
    "Content-Length" = 1011;
    "Content-Type" = "text/html;charset=utf-8";
    Date = "Wed, 21 Jan 2015 05:34:22 GMT";
    Server = "Apache-Coyote/1.1";
    "Set-Cookie" = "JSESSIONID=B2726D9C845F31BE9A68D06845E52080; Path=/WuNetbars/; HttpOnly";
} },

框架裏面
self.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/plain", @"text/html", nil]; 我都有啊

是請求頭的問題麼?求大神指點  javascript

終於搞好了,緣由是我用加密過的字符串,其中有加減等特殊符號,AFN框架直接處理字符串時會改變這些特殊符號和加些字符串,因此修改AFN內部這一部分便可 
html

  NSString *query = nil;
        if (self.queryStringSerialization) {
            NSError *serializationError;
            query = self.queryStringSerialization(request, parameters, &serializationError);

            if (serializationError) {
                if (error) {
                    *error = serializationError;
                }
                return nil;
            }

            query = (NSString *)parameters;
添加最後一句就行了,前面是AFN判斷修改的 
java

相關文章
相關標籤/搜索