cURL / Mailing Lists / curl-library / Single Mail

curl-library

curl exception with bad url

From: Robert Navarro <robobzzoy_at_gmail.com>
Date: Mon, 22 Aug 2011 17:52:51 -0400

Hi all,

I am seeing some strange behavior when trying to connect to a "bad"
url. I only say bad because the URL is correct, but when the system
receiving messages at that URL is down or not responding, I get an
exception instead of a timeout return.

FYI, this is a windows service application written in C++.

When the code below is executed with the receiving system running
fine, everything works as I expect it too, and I am able to get the
response data. However, if I set the URL to something bad (i.e.
http://222.222.222.222:14544/Page), or the receiver is not working
correctly, I receive an exception on curl_easy_perform, almost
immediately. I am hoping I am missing a silly option somewhere, but I
am not seeing it, so hopefully fresh eyes can point something obvious
out.

curl = curl_easy_init();
struct curl_slist *slist = NULL;;
slist = curl_slist_append(slist, "Expect:");
slist = curl_slist_append(slist, "Content-Type: text/xml");
if(curl)
{
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist);
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)&chunk);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 15);
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 15);
curl_easy_setopt(curl, CURLOPT_URL, m_sTrafficURL);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, xml_str);
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)xml_str.GetLength());
try
{
res = curl_easy_perform(curl);
}
catch (System::Exception* e) <--- catching this because I don't know
what else to catch, prevents service from stopping
{
  // logs exception Object reference not set to an instance of an object.
}
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2011-08-22