Thursday, November 3, 2011

Calling RESTful service under IOS5 failed with 401 error

Recently, we upgrade our iPad to IOS5, and xCode to 4.2 version,  after we done that I came across an issue. 

In our iPad application, we are calling the RESTful service on our server side, and we are using SSL and basic authentication, for most of the service call, it works fine, only two of the web services, the calls made from iPad application failed with 401 authentication error. 

The strange thing is , under IOS4.3.5 it works fine, only IOS 5 failed. 

after some investigation, I find out the RESTful service on our server, these two service that failed with 401, the url template is like /xxx/aaa/. while on the iPad application we are calling it as /xxx/aaa.

When I open Chrome and monitor the network request, I can actually see if we call it as /xxx/aaa, it get and HTTP 307 first, and redirect to /xxx/aaa/.

For some reason , IOS4 it works cause the basic authentication will be carry over to the next redirect request. while on IOS5, basic authentication will be dropped on the coming redirect request. that's why my service call fail, I change the code to call service like /xxx/aaa/ , then it all works. 

write down this just in case some other people also experiencing the same issue, so they can save a little bit time.