I'm having trouble calling Http.send on an API that requires basic authentication. I collapsed the key part down into a single function:
httpGet : JsonDecode.Decoder value -> String -> String -> Task.Task Http.Error value
httpGet decoder authorization url =
let request =
{ verb = "GET"
, headers =
[ ("Access-Control-Request-Method", "GET")
, ("Authorization", "Basic " ++ authorization)
]
, url = url
, body = Http.empty }
in
Http.fromJson decoder (Http.send Http.defaultSettings request)
I believe the API endpoint has CORS configured properly:
< Date: Thu, 25 Aug 2016 02:38:57 GMT
< Content-Type: application/json
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Methods: GET, POST, OPTIONS
< Access-Control-Allow-Headers: DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type
The problem I'm seeing is that when I trigger the Http.send in Chrome and Firefox, I only ever see an OPTIONS request returning 204 in the network tab. I never see the corresponding GET request and the Http.send function returns a very unhelpful NetworkError.
Can anybody point out what I am doing wrong?
Thanks,
Bryan