HTTPc get request does not work with 404 when auth headers are enabled

I am using Erlang httpc to request a request with parameters and with a basic auth header. When used without a header in httpc / 1, for example:

 url = String.to_char_list("https://endpoint.com/endpoint?param=foo")
 :httpc.request(url)

I get the expected 403 unauthorized. However, when I use httpc / 4 as follows:

 url = String.to_char_list("https://endpoint.com/endpoint?param=foo")
 headers = headers ++ [authheader]
 httpc.request(:get, {url, headers}, [], [])

I get 404 not found error. I can IO.put url and access the resource successfully when adding auth header manually from browser. My mail routes all work fine with httpc / 4. What's going on here?

+4
source share
1 answer

This is most likely a spelling mistake in the URL. That means using basic auth in httpc looks to me.

:httpc.request(:get, {'http://localhost:8080/', [{'Authorization', 'Basic ' ++ :base64.encode_to_string('test:test')}]}, [], [])
{:ok, {{'HTTP/1.0', 200, 'OK'}, ...}

URL-, URL- 401:

:httpc.request(:get, {'http://localhost:8080/asdf', []}, [], [])
{:ok, {{'HTTP/1.0', 401, 'Unauthorized'}, ...}

:

:httpc.request(:get, {'http://localhost:8080/asdf', [{'Authorization', 'Basic ' ++ :base64.encode_to_string('test:test')}]}, [], [])
{:ok, {{'HTTP/1.0', 404, 'File not found'}, ...}

, ssl, .

, http https. URL- https:// .

"403 ", - 401. 403 , , , 401.

httpc.request(...), .

Beyond the hint: you can use 'text'(in single quotes) instead String.to_character_list("text").

0
source

All Articles