[erlang-questions] Sometime it's the simple stuff...
Dave Bryson
daveb@REDACTED
Mon May 5 14:32:08 CEST 2008
Thanks Ingela. That's the approach I'm using now. Although I didn't
think about using "tuple_to_list()". I was patten matching on the
tuple:
{A,B,C,D} = {10,0.1.100}. You approach is cleaner.
Thanks again,
Dave
On May 5, 2008, at 2:12 AM, Ingela Anderton Andin wrote:
>> I need to take an IP address in the form of "[{10,0,1,100}]" and
>> create an http URL like this: "http://10.0.1.100/". I've tried
>> using
>> io_lib:format and successfully generated a list. But, the inets http
>> client doesn't like the format and complains of a malformed URL.
>
> Here I use io_lib:format to create a URL-string from your exampel (I
> guess that you mean that you have the ip-address on tupel
> format and not that you have a string looking like "[{10,0,1,100}]")
> and
> the inets client will parse it just fine. I did not do http:request
> as I have
> no server at this address...
>
> 1> URL = lists:flatten(io_lib:format("http://~w.~w.~w.~w/",
> tuple_to_list({10,0,1,100}))).
> "http://10.0.1.100/"
> 2> http_uri:parse(URL).
> {http,[],"10.0.1.100",80,"/",[]}
>
> ... but to prove my point I can do:
>
> 3> http:request(URL).
> {error,econnrefused}
>
> ... e.i it tried to call gen_tcp:connect and got connection refused,
> hence it has already parsed the URL
> successfully.
>
> But if you miss out one of the first "/" for instance:
>
> 4> http_uri:parse("http:/10.0.1.100/").
> {error,{malformed_url,"http:/10.0.1.100"}}
>
> 5> http:request("http:/10.0.1.100/").
> {error,{malformed_url,"http:/10.0.1.100"}}
>
> Maybe you missed something?
>
> Regards Ingela -OTP team
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
More information about the erlang-questions
mailing list