Erlang error received unexpected tcp data on #Port

I am retrieving a url with the following code:

geturl(Url)->
{ok, RequestId}=httpc:request(get,{Url,[{"User-Agent", "Opera/9.80 (Windows NT 6.1; U; ru) Presto/2.8.131 Version/11.10"}]}, [],[{sync, false}]),
  M = receive
        {http, {RequestId, {_HttpOk, _ResponseHeaders, _Body}}} -> ok 
      after 20000 ->
        not_ok
      end.
 io:format("httprequest to ~p: ~p~n",[UrlHTTP,M]).

Sometimes I see the following error output:

httprequest to "http://www.afbudsrejser.dk": ok
=ERROR REPORT==== 30-Apr-2014::16:53:49 ===
Received unexpected tcp data on #Port<0.4432>
   Data:       <<"\" type=\"text/javascript\"></script>\r\n\t</body>\r\n</html>\r\n\n">>
   MFA:        undefined
   Request:    undefined
   Session:    {session,{{"www.afbudsrejser.dk",80},<0.4392.0>},
                        false,http,#Port<0.4432>,ip_comm,1,pipeline,true}
   Status:     pipeline
   StatusLine: undefined
   Profile:    httpc_manager

Erlang error received unexpected tcp data in #Port

What is the reason for this error message?

+4
source share
1 answer

The HTTP server you are connecting to is incorrect. It declares a header Content-Lengththat is shorter than the response it actually sends.

, , ( type="text/javascript"></script>), httpc, HTTP. httpc , , , HTTP.

, . relaxed httpc option, .

+1

Source: https://habr.com/ru/post/1538735/


All Articles