ASIHTTPRequest:检查用户名/密码是否正确

时间:2021-11-20 16:54:29

How can I check a webservice if the username/password is correct?

如果用户名/密码正确,我该如何检查网络服务?

I don't want to transfer the whole response body. I only want to know if the username/password exists and is correct. Currently I'm sending a request to my webservice like this:

我不想转移整个回复机构。我只想知道用户名/密码是否存在且是否正确。目前我正在向我的网络服务发送请求,如下所示:

self.request = [ASIHTTPRequest requestWithURL:urlObject];
[self.request setUsername:username];
[self.request setPassword:password];
[self.request addRequestHeader:@"Accept" value:@"application/json"];
[self.request setDelegate:self];
[self.request startAsynchronous];

If I access the webservice with a browser and I insert a wrong password, I again get the authentication dialog displayed. I tried the same in Xcode and I get a status code = 200 if password was wrong. I thought I can do that with the status codes like 401 and so on. But that didn't worked, because I always get status code = 200. Do I have to change something on the serverside?

如果我使用浏览器访问Web服务并且插入了错误的密码,我将再次显示身份验证对话框。我在Xcode中尝试了相同的操作,如果密码错误,我会得到状态码= 200。我以为我可以用401等状态代码来做到这一点。但这没有用,因为我总是得到状态代码= 200.我是否必须在服务器端更改某些内容?

I'm using a REST webservice, which uses Restlet 2.0 as Java framework. Docs

我正在使用REST Web服务,它使用Restlet 2.0作为Java框架。文件

1 个解决方案

#1


0  

I'm still not sure exactly how your webservice works, but from the information given I think I can answer your question.

我仍然不确定您的网络服务是如何工作的,但根据给出的信息,我认为我可以回答您的问题。

If you are getting 'requestFailed:' when the username and password is wrong, then you should be able to avoid downloading the response body by using:

如果您在用户名和密码错误时收到'requestFailed:',那么您应该能够避免使用以下命令下载响应正文:

[request setRequestMethod:@"HEAD"];

#1


0  

I'm still not sure exactly how your webservice works, but from the information given I think I can answer your question.

我仍然不确定您的网络服务是如何工作的,但根据给出的信息,我认为我可以回答您的问题。

If you are getting 'requestFailed:' when the username and password is wrong, then you should be able to avoid downloading the response body by using:

如果您在用户名和密码错误时收到'requestFailed:',那么您应该能够避免使用以下命令下载响应正文:

[request setRequestMethod:@"HEAD"];