This is part of code of my project.
URL="http://www.amazon.com",
HTTPOpts = [{autoredirect, false}],
case httpc:request(get, {URL, [{"User-Agent", "Mozilla"}]}, HTTPOpts, []) of
{ok, {{_, Code, _}, Headers, Body}} when Code == 200 ->
%%code for process code=200 %%
{ok, {{_, Code, _}, Headers, _}} when Code < 310 , Code >= 300 ->
%% redirection
{ok, {{_, Code, _}, Headers, _}} when Code ==503 ->
%%service unavailable
The problem is when I perform http
request, it returns different status Code.
In case of URL
above I'm getting two responses, Code = 200
and Code = 503
, how do I handle this, so that I always get Code = 200
I also tried it using wget "www.amazon.com"
, it gives same result.
My idea: re-request in case of Code = 503
, but problem with this it may go into loop and may never return Code = 200
or return after several iterations, which produce delay in client request.
How to resolve it?