cURL / Mailing Lists / curl-users / Single Mail

curl-users

Re: Cannot resolve localhost or 127.0.0.1

From: weiping guo <weiping_guo_at_yahoo.com>
Date: Fri, 11 Jan 2008 11:12:30 -0800 (PST)

Sorry, my bad. My original code looks like this.

char url[REQUEST_LEN*2];
 memset(url,0, REQUEST_LEN*2);
int n = sprintf(url, "http://%s:%d/%s?%s", this->ip_, this->port_, this->url_, request);

It seems that curl is trying to cache the DNS entry. For the first time to call this function, it always return an error. Subsequent calls never fail.

Any suggestions.

Thanks.

Weiping

----- Original Message ----
From: weiping guo <weiping_guo_at_yahoo.com>
To: curl-users_at_cool.haxx.se
Sent: Friday, January 11, 2008 1:26:54 PM
Subject: Cannot resolve localhost or 127.0.0.1

Hi All,

I need some help on this problem.

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

I have the following code snippet:

if( !this->curl_init_)
{
  curl_global_init(CURL_GLOBAL_ALL);
  this-> curl_init_ = true;
}
conn = curl_easy_init();
if( conn == NULL )
{
  return -1;
}

CURLcode code;
code = curl_easy_setopt(conn, CURLOPT_ERRORBUFFER, this->error_buffer_);
if( code != CURLE_OK )
{
  return -1;
}

//composite the requested url
// http://127.0.0.1:8000/
char url[REQUEST_LEN*2];
    memset(url,0, REQUEST_LEN*2);
int n = sprintf(url, "// http://127.0.0.1:8000/connector", this->proxy_ip_, this->proxy_port_, this->proxy_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.

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.

Thanks.
Weiping

      ____________________________________________________________________________________
Looking for last minute shopping deals?
Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping

      ____________________________________________________________________________________
Never miss a thing. Make Yahoo your home page.
http://www.yahoo.com/r/hs
Received on 2008-01-11