简体   繁体   English

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

[英]ASIHTTPRequest: check if username/password is correct

How can I check a webservice if the username/password is correct? 如果用户名/密码正确,如何检查Web服务?

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: 目前,我正在向Web服务发送如下请求:

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. 如果使用浏览器访问Web服务并输入了错误的密码,则会再次显示身份验证对话框。 I tried the same in Xcode and I get a status code = 200 if password was wrong. 我在Xcode中尝试了相同的操作,如果密码错误,我得到的状态码= 200。 I thought I can do that with the status codes like 401 and so on. 我以为我可以使用401等状态代码来做到这一点。 But that didn't worked, because I always get status code = 200. Do I have to change something on the serverside? 但这没有用,因为我总是得到状态码=200。我是否必须在服务器端更改某些内容?

I'm using a REST webservice, which uses Restlet 2.0 as Java framework. 我正在使用REST Web服务,该服务使用Restlet 2.0作为Java框架。 Docs 文件

I'm still not sure exactly how your webservice works, but from the information given I think I can answer your question. 我仍然不确定您的Web服务的确切运行方式,但是从给出的信息来看,我认为我可以回答您的问题。

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"];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM