3

I am using the Alamofire 4.0.1 library in swift 3; I am looking for the HTTP Status-Line (as described in https://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html). I can get the status code, the headers, everything, but not the status message.

I am querying a REST API which gives me 403 responses with different messages after the "Forbidden" keyword describing the problem: like the client is not approved for access or that accessing an specific URL is not allowed, because it is for internal use only. In my client accessing the API I want to give the user more details than just the "Forbidden" message.

This is what the server sends back (I know this because I used Paw, a HTTP Client to send a HTTP request and investigate the response):

HTTP/1.0 403 Forbidden (internal method)

So to conclude, is there any chance to get the HTTP Status-Line in Alamofire?

rsc
  • 115
  • 2
  • 6
  • Its pretty uncommon (I've never heard of it) to use the status-line to pass an error message. It would be much more common to use 403 and include a message in the body of the response, in a JSON object or whatever format makes sense for you. – mcfedr Nov 07 '16 at 12:08
  • Thanks for your input, I forwarded the feedback to the API owner. – rsc Nov 07 '16 at 21:40

1 Answers1

1

Unfortunately no

Alamofire uses the URLResponse and it does not implement any field/method that gives you information about Status-Line. To get the Status-Line you should use other maybe lower-level frameworks.

URLResponse gives you only information about allHeaderFields, you can look on my answer about it here :

https://stackoverflow.com/a/36524454/5433235

Community
  • 1
  • 1
kamwysoc
  • 6,709
  • 2
  • 34
  • 48
  • Here you have similar question http://stackoverflow.com/a/18905087/5433235 – kamwysoc Nov 07 '16 at 12:10
  • Not exactly what I wanted to hear, but thank you for confirming it's not supported. I need to talk to that API guy :-) – rsc Nov 07 '16 at 15:58