开发者

Objective-C NSURLConnection with RESTful web service, error handling

开发者 https://www.devze.com 2023-02-25 18:04 出处:网络
I´m connection to a RESTful web service, using JSON to retrive data. The problem i have is that the server gives a 200 OK response even if the username and password is wrong. It then responds with a

I´m connection to a RESTful web service, using JSON to retrive data. The problem i have is that the server gives a 200 OK response even if the username and password is wrong. It then responds with a html page with instructions. I wa开发者_如何学Pythonnt to do some error handling when a user is logging in, is there a way in Objective-C to check the content-type of the response and compare that to "application/json"?

Thanks in advance!


The NSURLResponse class has a MIMEType property which I think can be used.

Or, for HTTP, there is the allHeaderFields on NSHTTPURLResponse which returns a dictionary of the response headers (then you just check the Content-Type header).

0

精彩评论

暂无评论...
验证码 换一张
取 消