它似乎在网络上工作:
网络回复标题:
Connection:keep-alive
Content-Length:394
Content-Type:application/json
Date:Sun, 22 Mar 2015 18:36:06 GMT
Server:nginx/1.6.2
Vary:Accept-Encoding
X-Powered-By:Express
Web请求标题:
Accept:application/json, text/plain, */*
Accept-Encoding:gzip, deflate
Accept-Language:en-US,en;q=0.8
Authorization:Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJfaWQiOiI1NDVjYzNjYzQ2N2I3YjAyMDBhMWNkOWEiLCJpYXQiOjE0MjcwNDM3Mzk1NjQsImV4cCI6MTQ5MDExNTczOTU2NH0.Xqm-b12QWcEa6MPXyKa1E8m88hGZI9KfJl7Img3mACU
Connection:keep-alive
Content-Length:225
Content-Type:application/json;charset=UTF-8
网络请求有效负载:
{"id":"550f15122cc2708c2d9c65b8","users":["xiruken@gmail.com"],"welcomeMessage":"Hi there. We’ll be using Next24 to keep track of our daily high priority items as a group during this project.","newUser":"xiruken@gmail.com"}
但是没有使用Objective-C在我的原生iOS项目中工作......
相同的参数:
NSDictionary
查询:
{
id = 550f15122cc2708c2d9c65b8;
newUser = "xiruken@gmail.com";
users = (
"xiruken@gmail.com"
);
welcomeMessage = "Hi there. We will be using Next24 to keep track of our daily high priority items as a group during this project.";
}
AFNetworking
代码:
-(AFHTTPSessionManager *)sessionManager2{
if(!_sessionManager2){
_sessionManager2 = [[AFHTTPSessionManager alloc] initWithBaseURL: [NSURL URLWithString:API_URL]];
AFSecurityPolicy *securityPolicy = [[AFSecurityPolicy alloc] init];
[securityPolicy setAllowInvalidCertificates:YES];
[_sessionManager2 setSecurityPolicy:securityPolicy];
_sessionManager2.responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions: NSJSONReadingAllowFragments];
NSArray *acceptedTypes = @[@"text/html", @"application/json", @"text/plain"];
_sessionManager2.responseSerializer.acceptableContentTypes = [NSSet setWithArray:acceptedTypes];
//add token
if([Helpers isLoggedIn]){
UserDM *user = [UserDM loadCustomObjectWithKey:DEFAULT_CURRENT_USER];
[self.sessionManager2.requestSerializer setValue:[NSString stringWithFormat:@"Bearer %@", user.accessToken] forHTTPHeaderField:@"Authorization"];
}
}
return _sessionManager2;
}
使用AFJSONResponseSerializer
给了我这个错误:
2015-03-23 03:28:26.773 Next25[5801:302572] Failed! Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (Invalid value around character 0.) UserInfo=0x7fdbb252a6e0 {NSDebugDescription=Invalid value around character 0., NSUnderlyingError=0x7fdbb252c410 "Request failed: internal server error (500)"}
我甚至allowFragments
甚至设置acceptableContentTypes
将其更改为AFHTTPResponseSerializer
会给我一个不同的错误:
2015-03-23 03:30:30.797 Next25[5852:303849] Failed! Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: internal server error (500)" UserInfo=0x7fb129e4e930 {com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x7fb129e36320> { URL: https://myproject.com/api/projects/550f15122cc2708c2d9c65b8/invite_users } { status code: 500, headers {
Connection = "keep-alive";
"Content-Length" = 21;
"Content-Type" = "text/html";
Date = "Sun, 22 Mar 2015 19:26:56 GMT";
Server = "nginx/1.6.2";
Vary = "Accept-Encoding";
"X-Powered-By" = Express;
} }, NSErrorFailingURLKey=https://myproject.com/api/projects/550f15122cc2708c2d9c65b8/invite_users, com.alamofire.serialization.response.error.data=<496e7465 726e616c 20536572 76657220 4572726f 72>, NSLocalizedDescription=Request failed: internal server error (500)}