我正在尝试在 https 上进行 HTTP 调用。这是我的代码片段。
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]
initWithURL:[NSURL
URLWithString:@"https://testservice.fiamm.com/token"]];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-type"];
NSString *postString = @"username=TestIphone&Password=T3st1ph$n&Grant_type=password";
[request setValue:[NSString stringWithFormat:@"%d", [postString length]] forHTTPHeaderField:@"Content-length"];
[request setHTTPBody:[postString
dataUsingEncoding:NSUTF8StringEncoding]];
// Fetch the JSON response
NSData *urlData;
NSURLResponse *response;
NSError *error;
// Make synchronous request
urlData = [NSURLConnection sendSynchronousRequest:request
returningResponse:&response
error:&error];
// Construct a String around the Data from the response
NSString *strFiamm = [[NSString alloc] initWithData:urlData encoding:NSUTF8StringEncoding];
当我尝试 throw 或 postman 时,我得到了正确的响应,但是当我尝试使用我的代码时,我得到了这个错误。
NSURLConnection/CFURLConnection HTTP 加载失败(kCFStreamErrorDomainSSL,-9813)
任何帮助或建议表示赞赏。!
最佳答案
你在这里提到的链接不是 https 证书,所以使用简单的 http 而不是 https
编辑 #1
我试过这些值
http://testservice.fiamm.com/token
username=TestIphone
Password=T3st1ph$n
Grant_type=password
和输出是
403 - Forbidden: Access is denied.
You do not have permission to view this directory or page using the credentials that you supplied.
这意味着您的用户名密码或 key 值不正确
关于objective-c - NSURLConnection/CFURLConnection HTTP 加载失败(kCFStreamErrorDomainSSL,-9813),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30420345/