相关疑难解决方法(0)

iOS中的NSURLConnection和基本HTTP身份验证

我需要GET HTTP request用Basic 调用一个初始化Authentication.这将是第一次将请求发送到服务器并且我已经拥有了username & password这样的服务,因此不需要服务器进行授权的质询.

第一个问题:

  1. 是否NSURLConnection必须设置为同步才能执行Basic Auth?根据这篇文章的答案,如果你选择异步路由,似乎你不能做Basic Auth.

  2. 任何人都知道任何一些示例代码,说明了基本GET request身份验证,而无需质询响应?Apple的文档显示了一个示例,但仅在服务器向客户端发出质询请求之后.

我是SDK的新网络部分,我不确定我应该使用哪个其他类来实现这个功能.(我看到了NSURLCredential类,但它似乎只NSURLAuthenticationChallenge在客户端请求来自服务器的授权资源之后才使用它).

iphone objective-c nsurlconnection ios

84
推荐指数
4
解决办法
9万
查看次数

iPhone上的基本HTTP身份验证

我正在尝试运行一个小型的Twitter客户端,在测试需要身份验证的API调用时遇到了问题.

我的密码中包含特殊字符,因此当我尝试使用以下代码时,它不起作用.

NSString *post = [NSString stringWithFormat:@"status=%@", [status stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSData *postData = [post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];

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

NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@:%@@%@/statuses/update.json", username, password, TwitterHostname]];
[request setURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];

NSURLResponse *response;
NSError *error;
[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
Run Code Online (Sandbox Code Playgroud)

我开始研究base64并将身份验证放入标头中.我在他的base64实现中发现了Dave Dribin的帖子,这看起来很有道理.但是,当我尝试使用它时,编译器开始抱怨它无法找到openssl库.所以我读到我需要在libcrypto库中链接,但它似乎不存在于iphone.

我还读过有人说苹果不会允许使用加密库的应用程序,这对我来说没有意义.

所以现在我有点困惑和困惑.在我的应用程序中获取基本身份验证的最简单方法是什么?

干杯

iphone objective-c httpwebrequest http-authentication

13
推荐指数
1
解决办法
2万
查看次数