Using inets http client
Michael McDaniel
erlang@REDACTED
Sat Jun 4 21:37:59 CEST 2005
On Sat, Jun 04, 2005 at 06:30:44PM +0100, Will Newton wrote:
>
> Following the documentation of the inets http client I have written this code:
>
> http_wait_with_timeout(RequestId, Timeout) ->
> if
> Timeout > 0 ->
> receive
> {http, {RequestId, Result}} ->
> Result;
> {http, {RequestId, {error, Reason}}} ->
> throw({error, Reason})
> after
> 1000 ->
> io:format(".")
> end,
> http_wait_with_timeout(RequestId, Timeout - 1000);
> true ->
> throw({timeout})
> end.
>
> get_url(Url) ->
> application:start(inets),
> case http:request(get, {Url, []}, [], [{sync, false}]) of
> {ok, RequestId} ->
> http_wait_with_timeout(RequestId, 15000);
> _ ->
> io:format("http request failed~n")
> end.
>
> I get a series of periods printed but I never get the expected response from
> the async http request. Can anyone tell me what am I doing wrong?
>
> Thanks,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
per documentation of http.html ,
(on my system, at http:///usr/local/lib/erlang/doc/index.html and choose http.html)
" request(Method, Request, HTTPOptions, Options) -> {ok, Result} | {error, Reason} "
It appears that when the http:request/4 returns (successfully),
http_wait_with_timeout(RequestId, 15000) is then called and prints dots.
I suggest adding
io:format'~p~n', [RequestId]) ,
just before the call to http_wait_with_timeout(RequestId, 15000) in get_url/1
and see what gets printed.
~Michael
More information about the erlang-questions
mailing list