我在 ios 应用程序中使用 salesforce live agent rest api,尝试请求聊天但总是以 400 请求失败,这不是有效的 ChasitorInit
NSDictionary *parameters =@{ @"SessionId" :self.sessionId,
@"OrganizationId" :ORG_ID,
@"deploymentId" :DEPLOYEMENT_ID,
@"buttonId" :BUTTON_ID,
@"userAgent" :USER_AGENT,
@"language" :LANG,
@"screenResolution" :SCREEN_RES,
@"visitorName" :@"Test Visitor",
@"prechatDetails" :@[],
@"prechatEntities" :@[],
@"receiveQueueUpdates":@"true",
@"isPost" :@"true"
};
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
AFJSONRequestSerializer *serializer = [AFJSONRequestSerializer serializer];
[serializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[serializer setValue:@"application/json" forHTTPHeaderField:@"Accept"];
manager.requestSerializer = serializer;
[manager.requestSerializer setValue:self.sessionKey forHTTPHeaderField:X_LIVEAGENT_SESSION_KEY];
[manager.requestSerializer setValue:@"null" forHTTPHeaderField:X_LIVEAGENT_AFFINITY];
[manager.requestSerializer setValue:@"1" forHTTPHeaderField:X_LIVEAGENT_SEQUENCE];
[manager.requestSerializer setValue:API_V forHTTPHeaderField:X_LIVEAGENT_API_VERSION];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
[manager POST:ChasitorInit_path parameters:parameters progress:nil
success:^(NSURLSessionDataTask *task, id responseObject) {
NSError* error;
NSDictionary* json = [NSJSONSerialization JSONObjectWithData:responseObject
options:kNilOptions
error:&error];
} failure:^(NSURLSessionDataTask *task, NSError *error) {
NSLog(@"Error: %@", error);
}];
我正在使用 Afnetworking v3 ios8 请求正文应该是
{
"sessionId": "8f1cfb18-fbd1-4487-90d-e98c0a84e165",
"organizationId": "00D58000000OwMB",
"deploymentId": "57258000000L1mj",
"buttonId": "57358000000L24F",
"userAgent": "",
"language": "en-US",
"screenResolution": "1900x1080",
"visitorName": "Test Visitor",
"prechatDetails": [],
"prechatEntities": [],
"receiveQueueUpdates": true,
"isPost": true
}
我做错了什么?请纠正我!