0

实际上我想从服务器获取数据。当我使用 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 获得了它,它是 RESTful Web 服务的调试器。但我没有使用我的代码。请任何人帮助我解决问题所在。提前致谢。

4

1 回答 1

0

I used the following to perform successful Digest Auth using ASIHTTPRequest. Can be modified to make it Async.

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];
}
于 2012-11-30T01:23:52.443 回答