objective-c - NSURLConnection/CFURLConnection HTTP 加载失败(kCFStreamErrorDomainSSL,-9813)

标签 objective-c iphone http nsurlrequest nsmutableurlrequest

我正在尝试在 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];

当我在 hurl 或 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.

这意味着您的用户名密码或键值不正确

关于objective-c - NSURLConnection/CFURLConnection HTTP 加载失败(kCFStreamErrorDomainSSL,-9813),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30420345/

相关文章:

IOS Swift - 使用容器 View 在 View Controller 之间传递数据

http - Angular.js $http $window.location 和全局变量

ruby-on-rails - 关于 HTTP 身份验证方案的建议(使用请求 header )

objective-c - UICollectionView 类似于 iOS 主屏幕

ios - 如何避免核心数据警告 "Entity should have an inverse relationship"?

css - iPhone Web App Div 标签在 Safari 中重新加载

iPhone操作系统: Tap status bar to scroll to top doesn't work after remove/add back

java - 使用 Java 调用 AWS Lambda 上的 Web 服务

ios - 将 BOOL 类型的默认值设置为 YES

objective-c - 使用 RestKit 搜索 CoreData