[Fwd: http client hell]
Ingela Anderton
ingela@REDACTED
Wed Dec 8 09:58:30 CET 2004
blaguehubert wrote:
> I'm trying to use the http:request function, but I randomly get this
>
> horrible message before it crash my program:
>
> *=ERROR REPORT==== 7-Dec-2004::23:39:22 ===
> ** Generic server <0.64.0> terminating
> ** Last message in was {tcp_closed,#Port<0.137>}
> ** When Server state == {state,{request,
> #Ref<0.0.0.822>,
> <0.114.0>,
> 0,
> http,
> {"perso.efrei.fr",80},
> "/~colombi//",
> [],
> get,
> {http_request_h,
> undefined,
> "keep-alive",
> undefined,
> undefined,
> undefined,
> undefined,
>
> etc...
You cut out the most interesting part e.i. the reason for the
termination. That the tcp port was closed might be perfectly normal
as many servers close the connection to indicate that the whole answer
has been sent instead of sending a length indicator.
Which version of intes are you using?
> Here is my code :
> *
> req(Url) ->
> case (catch req(Url,10)) of
> {ok, Body} ->
> {ok, Body};
> _ ->
> error
> end.
>
> req(Url, NbTry) ->
> {ok, RequestId} = http:request(get, {Url, []}, [], [{sync, false}]),
> receive
> {http, {RequestId, Result}} ->
> {N, Header, Body} = Result,
> {ok, binary_to_list(Body)}
> after 60000 ->
> if
> NbTry) > 0 ->
> req(Url, NbEssais-1);
> true ->
> error
> end
> end.
>
> Like you can see, I use catch statement and timeout because I thought it
> was only an exception, but it seems more serious...
I fixed your code above as it did not compile. And this is the result I get
every time I try it with intes-4.0.1
3> test:req("http://perso.efrei.fr:80/~colombi/").
{ok,"<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\n<head>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />\n <title>No title</title>\n <meta name=\"generator\" content=\"amaya 8.5, see http://www.w3.org/Amaya/\" />\n</head>\n\n<body>\n<p>un lien de test: <a href=\"./ici.html\">ici</a></p>\n</body>\n</html>\n"}
Your code fixed:
-module(test).
-export([req/1]).
req(Url) ->
case (catch req(Url,10)) of
{ok, Body} ->
{ok, Body};
_ ->
error
end.
req(Url, NbTry) ->
{ok, RequestId} = http:request(get, {Url, []}, [], [{sync, false}]),
receive
{http, {RequestId, Result}} ->
{_N, _Header, Body} = Result,
{ok, binary_to_list(Body)}
after 60000 ->
if
NbTry > 0 ->
req(Url, NbTry-1);
true ->
error
end
end.
--
/Ingela
Ericsson AB - OTP team
More information about the erlang-questions
mailing list