不在 WiFi 上时需要 ASIHTTPRequest 身份验证,并提供凭据
我在 ASIHTTPRequest 中遇到一些奇怪的行为。
我正在尝试连接到一个网站,该网站提示用户在加载页面时提供他/她的凭据。
为了使用 ASIHTTPRequest 实现此功能,我使用了以下代码:
NSURL *URL = [NSURL URLWithString:@"http://fhict.fontys.nl/Pages/Welkom.aspx"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:URL];
[request setUsername:theUsername];
[request setPassword:thePassword];
[request setDelegate:self];
[request startAsynchronous];
我确信为请求提供的凭据是正确的, 当我使用 WiFi 时,请求成功并且应用程序继续。
但是当我连接到蜂窝网络时,完全相同的请求会出现错误: 错误:错误域=ASIHTTPRequestErrorDomain代码=3“需要身份验证”UserInfo=0x2e8ef0 {NSLocalizedDescription=需要身份验证}
我检查过,当凭据不正确时会出现同样的错误,但我已经仔细检查过它们并且它们是正确的!
为了解决这个问题,我尝试过:
- 将超时设置为 2 分钟(我知道这有点过分,但只是为了测试),这会导致
- 启用相同的错误并为 WWAN 设置带宽限制(如 http://allseeing-i.com/ASIHTTPRequest/How-to-use,搜索 WWAN),但没有更改
- 设置使能shouldPresentCredentialsBeforeChallange 并将 basichttpheader 添加到请求中,但随后 WiFi 也停止工作。
然后进行了大量谷歌搜索,仍然没有解决方案。
我有点困惑,因为在 WiFi 上一切都很完美,
我希望这里的任何人都能给我指出正确的方向。
I'm experiencing some strange behavior with the ASIHTTPRequest.
I'm trying to connect to a website which prompt a user to give his/her credentials when loading the page.
To implement this with ASIHTTPRequest i've used the following code:
NSURL *URL = [NSURL URLWithString:@"http://fhict.fontys.nl/Pages/Welkom.aspx"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:URL];
[request setUsername:theUsername];
[request setPassword:thePassword];
[request setDelegate:self];
[request startAsynchronous];
I'm sure the credentials given to the request are correct,
and when i'm working on WiFi the request succeeds and the app continues..
But when i'm connected to cellular network, the exact same request gives an error:
error:Error Domain=ASIHTTPRequestErrorDomain Code=3 "Authentication needed" UserInfo=0x2e8ef0 {NSLocalizedDescription=Authentication needed}
I checked, this same error is given when the credentials are incorrect, but i've double checked them and they are correct!
To fix this I've tried:
- setting the timeout on 2 minutes (overkill I know but just for testing), this resulted the same error
- enabled and set bandwidth throttling for WWAN (as described on http://allseeing-i.com/ASIHTTPRequest/How-to-use, search for WWAN), but nothing changed
- setting enabling shouldPresentCredentialsBeforeChallange and adding basichttpheader to the request, but then also WiFi stopped working..
And then a lot of googling later, still no solution.
I'm a little confused because because on WiFi everything works perfectly,
I hope anyone here can point me in the right direction..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
(在问题编辑中回答。已转换为社区 wiki 答案。请参阅 当问题的答案添加到问题本身时,适当的操作是什么?)
OP 写道:
(Answered in a question edit. Converted to a community wiki answer. See What is the appropriate action when the answer to a question is added to the question itself? )
The OP wrote: