iphone - https 上的 NSURLConnection 同步请求

标签 iphone authentication synchronous

谁能告诉我如何同步调用 https 服务器?我可以使用以下委托(delegate)方法在 https 服务器上执行异步请求。

- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace

- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge

但我需要进行同步。

最佳答案

//对请求进行编码

NSData *postData = [xmlText dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];

**//Calculating length of request**
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];

NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:requestUrlString]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/xml" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSURLResponse* response;
NSError* error = nil;

//Capturing server response
NSData* result = [NSURLConnection sendSynchronousRequest:request  returningResponse:&response error:&error];

关于iphone - https 上的 NSURLConnection 同步请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4613067/

相关文章:

JQuery同步动画

iphone - iOS - 在 UIWebView 中显示谷歌结果

java - 无法使用 Selenium 在 Element 上输入字符串

ios - WatchKit:存储在App Group中的动画图片

laravel - 传递给 App\Http\Controllers\Auth\LoginController::attemptLogin() 的参数 1 必须是 App\Http\Controllers\Auth\Request 的实例

python - 如何使用Python请求登录网站?

asynchronous - Dart - 区分同步和异步 void 回调

c# - 如何阻塞一个线程,直到另一个线程在 C# 中获得服务器响应

iphone - 在 UITableview 上禁用滑动和删除

iphone - @synthesize 干扰继承