i'm using erlang's httpc make request parameters , basic auth header. when used without header in httpc/1, this:
url = string.to_char_list("https://endpoint.com/endpoint?param=foo") :httpc.request(url) i expected 403 unauthorized. however, when use httpc/4 this:
url = string.to_char_list("https://endpoint.com/endpoint?param=foo") headers = headers ++ [authheader] httpc.request(:get, {url, headers}, [], []) i 404 not found error. can io.puts url , directly access resource when adding auth header manually browser. post routes work fine httpc/4. what's happening here?
this spelling mistake in url. is, how using basic auth in httpc looks me.
:httpc.request(:get, {'http://localhost:8080/', [{'authorization', 'basic ' ++ :base64.encode_to_string('test:test')}]}, [], []) {:ok, {{'http/1.0', 200, 'ok'}, ...} authenticating perfomed before checking url, can try connect non existing url , receive 401:
:httpc.request(:get, {'http://localhost:8080/asdf', []}, [], []) {:ok, {{'http/1.0', 401, 'unauthorized'}, ...} if add proper headers:
:httpc.request(:get, {'http://localhost:8080/asdf', [{'authorization', 'basic ' ++ :base64.encode_to_string('test:test')}]}, [], []) {:ok, {{'http/1.0', 404, 'file not found'}, ...} also, can't problem ssl, because gives different error.
there small chance, server has different routes http , https. way pasting url browser without https:// work.
in question, said "403 unauthorized", while unauthorized 401. 403 forbidden, forbidden doesn't make sense in context, assumed, meant 401.
there no colon before httpc.request(...) in question, makes simple spelling mistake more likely.
aside tip: can use 'text' (in single quotes) instead of string.to_character_list("text").
Comments
Post a Comment