小编Roc*_*cks的帖子

IOS中的HTTPS发布请求

我试图通过使用以下代码发出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];
Run Code Online (Sandbox Code Playgroud)

但是我得到了回应.

error Error Domain = NSURLErrorDomain Code = …

objective-c ios

3
推荐指数
1
解决办法
9020
查看次数

标签 统计

ios ×1

objective-c ×1