cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Error: Cannot resolve localhost

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Fri, 11 Jan 2008 22:48:21 +0100 (CET)

On Fri, 11 Jan 2008, weiping guo wrote:

> I have a very simple program to post some data to webpage in the localhost.

What libcurl version on what operating system? Do you build libcurl IPv6
enabled or with c-ares support?

> char url[REQUEST_LEN*2];

How big is REQUEST_LEN ?

> int n = sprintf(url, "http://%s:%d/%s?%s", this->ip_, this->port_,
> this->url_, request);
>
> code = curl_easy_setopt(conn, CURLOPT_URL, url);
> if( code != CURLE_OK )
> {
> return -1;
> }
>
> code = curl_easy_perform(conn);
> curl_easy_cleanup(conn);
>
>
> However, I got the error code CURLE_COULDNT_RESOLVE_HOST. This error is
> happened if this function is called for the first time. The subsequent calls
> would be all right.

That really makes no sense to me (if you're actually are using an IP address
in there as the code hints). I would rather guess that either you're not
showing us the exact code you're actually using here, or something in your
code is misbehaving memory wise or similar.

libcurl doesn't resolve plain IP addresses at all, so I don't think it can
even return that error on such an input.

When you speak of subsequent ones, do you mean that entire flow repeated
again? Since it closes the handle, all code will run the exact same way the
second time and thus I would say that indicates that the source of this
problem is outside of libcurl. (Assuming that you pass in a hostname then,
since when it isn't a hostname I can't explain the return code at all...)

> I do not know how to make it work for the first call. I am currently using
> an ugly workaround, ˙˙call this function in the constructor˙˙. Any help or
> suggestions are appreciated.

gdb or strace will of course help you figure out the root of this.

-- 
  Commercial curl and libcurl Technical Support: http://haxx.se/curl.html
Received on 2008-01-11