我有一个存储在以下位置的 api:
https://my-api-site.com
如果我使用以下代码访问它,我通过帖子将我的登录密码传递给服务器,我的数据是否从我的 iPhone 应用程序嵌入到服务器/api?
NSURL *url = [NSURL URLWithString:@"https://my-api-site.com"];
//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];
到服务器的应用程序是否发送加密数据?
由于您使用的是https连接。是的,它是SSL/TLS加密的。您可以免受 MitM 攻击。
在互联网上的流行部署中,HTTPS提供了 网站和与之关联的网络服务器的身份验证 是通信,可以防止中间人攻击。 此外,它还提供通信的双向加密 在客户端和服务器之间,防止窃听和 篡改或伪造通信内容。
更多信息
HTTPS 连接
Https 连接是安全的,但如果数据太重要,您也可以使用 Base64 加密或 AES 加密通过网络发送数据。您必须先加密这些值,然后将这些值作为字典发送到正文中。