iOS 调用push api返回bad request (400)
先附上代码
NSURL *baseUrl = [NSURL URLWithString:@"https://api.jpush.cn"];
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"json" inDirectory:@"JsonData"];
NSData *data = [NSData dataWithContentsOfFile:filePath];
NSError *error;
NSDictionary *jsonObject = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
AFHTTPSessionManager *httpSessionMgr = [[AFHTTPSessionManager alloc]initWithBaseURL:baseUrl];
[httpSessionMgr.requestSerializer setAuthorizationHeaderFieldWithUsername:AppKey password:MasterSecret];
[httpSessionMgr POST:@"v3/push" parameters:jsonObject success:^(NSURLSessionDataTask * _Nonnull task, id _Nonnull responseObject) {
NSLog(@"success");
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSLog(@"failed %@", error.description);
}];test.jonson的内容
{
"platform": "all",
"audience": "all",
"notification": {
"ios": {
"alert": "Hi, JPush!",
"sound": "default",
"badge": "+1",
"extras": {
"newsid": 321
}
}
},
"options": {
"time_to_live": 60,
"apns_production": false
}
}这是一个测试push api给自己的应用发送推送的测试工程。appkey和masterSecret都设置正确,运行后错误,显示failed Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: bad request (400)" UserInfo={com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x17003b640> { URL: https://api.jpush.cn/v3/push }
求助时代码哪里有问题导致了这个错误码?