gpt4 book ai didi

ios - IOS 中的 HTTPS post 请求

转载 作者:可可西里 更新时间:2023-11-01 17:08:47 24 4
gpt4 key购买 nike

我正在尝试使用以下代码发出 https 发布请求。

NSURL *url = [NSURL URLWithString:@"https://portkey.formspring.me/login/"];

//initialize a request from url
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[url standardizedURL]];

//set http method
[request setHTTPMethod:@"POST"];
//initialize a post data

NSDictionary *postDict = [NSDictionary dictionaryWithObjectsAndKeys:@"username", @"username",
@"password", @"password", nil];

NSError *error=nil;

NSData* jsonData = [NSJSONSerialization dataWithJSONObject:postDict
options:NSJSONWritingPrettyPrinted error:&error];



[request setValue:@"application/x-www-form-urlencoded; charset=utf-8" forHTTPHeaderField:@"Content-Type"];

//set post data of request
[request setHTTPBody:jsonData];

//initialize a connection from request
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];

//start the connection
[connection start];

但我收到以下回复。

error Error Domain=NSURLErrorDomain Code=-1202 "The certificate for this server is invalid. You might be connecting to a server that is pretending to be “portkey.formspring.me” which could put your confidential information at risk." UserInfo=0x7564180 {NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?, NSErrorFailingURLKey=https://portkey.formspring.me/login/, NSLocalizedDescription=The certificate for this server is invalid. You might be connecting to a server that is pretending >to be “portkey.formspring.me” which could put your confidential information at risk., NSUnderlyingError=0x7168a20 "The certificate for this server is invalid. You might be connecting to a server that is pretending to be “portkey.formspring.me” which could put your confidential information at risk.", NSURLErrorFailingURLPeerTrustErrorKey=}

谁能告诉我如何使用 NSURLConnection 发出发布请求?

提前致谢。

最佳答案

您尝试连接的网站的证书不受信任(请尝试访问您在 Chrome 中发布的链接)。

默认情况下,iOS 不允许您连接到提供不受信任证书的站点。如果绝对必要,您可以绕过此检查 - 请参阅此问题:How to use NSURLConnection to connect with SSL for an untrusted cert?

但是,实际修复有问题的证书会好得多。

关于ios - IOS 中的 HTTPS post 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16918697/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com