实际上我想从服务器获取数据。当我使用ASIHTTPRequest进行基本身份验证时,我没有收到任何错误。当我使用ASIHTTPRequest进行摘要认证时,我遇到了问题。
我的代码是:
ASIHTTPRequest *requestASI = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];//url is in https
[requestASI setValidatesSecureCertificate:NO];
//[requestASI setDelegate:self];
[requestASI setUsername:self.user_name];
[requestASI setPassword:self.pass_word];
[requestASI setAuthenticationScheme:(NSString *)kCFHTTPAuthenticationSchemeDigest];
[requestASI addRequestHeader:@"User-Agent" value:@"ASIHTTPRequest"];
[requestASI setRequestMethod:@"GET"];
// [requestASI startAsynchronous];
[requestASI startSynchronous];
我有如下......
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
Request header field is missing ':' separator.<br />
<pre>
hone OS 5.0; en_US)</pre>
</p>
<hr>
<address>Apache/2.2.16 (Fedora) Server at www.example.com Port 443</address>
</body></html>
实际上我必须得到如下......
<?xml version="1.0" encoding="UTF-8" ?>
<resource-lists xmlns="urn:ietf:params:xml:ns:resource-lists">
<list name="friends">
<entry uri="venkat">
<display-name>My name is Prasad</display-name>
</entry>
</list>
</resource-lists>
我使用RESTClient来获取它,RESTClient是RESTful Web服务的调试器。但我没有使用我的代码。请任何人帮我解决问题所在。 提前谢谢。
答案 0 :(得分:0)
我使用以下内容使用ASIHTTPRequest执行成功的Digest Auth。可以修改以使其成为异步。
NSString* urlString = @"http://yourURL";
NSURL* url = [NSURL URLWithString:urlString];
ASIHTTPRequest* request = [ASIHTTPRequest requestWithURL:url];
[request setDelegate:self];
request.shouldPresentCredentialsBeforeChallenge = YES;
[request setUsername:@"yourusername"];
[request setPassword:@"yourpassword"];
request.timeOutSeconds = 30;
request.validatesSecureCertificate = NO;
[request setRequestMethod:@"GET"];
[request setDidFinishSelector:@selector(sendRequestResponse:)];
[request setDidFailSelector:@selector(sendRequestResponse:)];
[request startSynchronous];
NSError *error = [request error];
if (!error) {
NSString *response = [request responseString];
}