curl / Mailing Lists / curl-library / Single Mail

curl-library

RE: image can't be downloaded from sharepoint server using libcurl (c++ code): HTTP/1.1 503 Service Unavailable

From: RHAIEM, Mohamed Slim via curl-library <curl-library_at_cool.haxx.se>
Date: Fri, 24 Nov 2017 13:27:57 +0000

Hi Daniel,

I'm getting this error while trying to get an image from a sharepoint server.
That image is already visible using the same link in the browser within the same machine where I can't get it using libcurl.
But I can't get it using the following code and I'm getting only an error (HTTP/1.1 503 Service Unavailable) :

  CURL* hCurl = curl_easy_init();
  if (! hCurl)
  {
    KTRACE_ERROR("Error: failed to create curl handle");
    return E_BO_FAIL;
  }

  // This option is needed for debug reasons
  // It permits to activate verbose mode
  curl_easy_setopt(hCurl, CURLOPT_VERBOSE, 1);

  char curlErrorMessage[CURL_ERROR_SIZE];
  CURLcode res = CURLE_OK;

  curl_easy_setopt(hCurl, CURLOPT_FOLLOWLOCATION, 1);

  if ( !m_dataProxyUrl.empty() )
    curl_easy_setopt(hCurl, CURLOPT_PROXY, m_dataProxyUrl.c_str());

  curl_easy_setopt(hCurl, CURLOPT_URL, reinterpret_cast<const char*>(m_url.c_str()));
  KTRACE_SHORT2( "Opening URL", m_url ) ;

  // data
  curl_easy_setopt(hCurl, CURLOPT_WRITEFUNCTION, dataWrite);
  curl_easy_setopt(hCurl, CURLOPT_FILE, &m_os);

  // errors and traces
  curl_easy_setopt(hCurl, CURLOPT_ERRORBUFFER, curlErrorMessage);
  curl_easy_setopt(hCurl, CURLOPT_NOPROGRESS, 1);

  //https
  curl_easy_setopt(hCurl, CURLOPT_SSL_VERIFYPEER, 0L);
  curl_easy_setopt(hCurl, CURLOPT_SSL_VERIFYHOST, 0L);

  curl_easy_setopt(hCurl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
  curl_easy_setopt(hCurl, CURLOPT_SSLVERSION, 1);
  curl_easy_setopt(hCurl, CURLOPT_FAILONERROR, false);

  try
  {
    // Open the stream BEFORE running the curl perform action
    OpenStream();
    res = curl_easy_perform(hCurl);
  }
  catch (...)
  {
    KTRACE_ERROR2("Error: failed to get distant file using libcurl", curlErrorMessage);
    downloadRes = E_BO_FAIL;
  }

  if (CURLE_OK == res) {
          char *ct;
          /* ask for the content-type */
          res = curl_easy_getinfo(hCurl, CURLINFO_CONTENT_TYPE, &ct);

          if ((CURLE_OK == res) && ct)
          {
                  UpdateMimeType(ct);
                  UpdateFileNames(ct);
          }
  }

  if (m_os)
    m_os.close();

  if (hCurl)
    curl_easy_cleanup(hCurl);

  if (res != CURLE_OK)
  {
    KTRACE_ERROR2("Error: failed to download resource", curlErrorMessage);
    return E_BO_FAIL;
  }

We're using libcurl 7.40.0.

Regards,
Slim

-----Original Message-----
From: Daniel Stenberg [mailto:daniel_at_haxx.se]
Sent: vendredi 24 novembre 2017 13:39
To: RHAIEM, Mohamed Slim via curl-library <curl-library_at_cool.haxx.se>
Cc: RHAIEM, Mohamed Slim <mohamed.slim.rhaiem_at_sap.com>
Subject: Re: image can't be downloaded from sharepoint server using libcurl (c++ code): HTTP/1.1 503 Service Unavailable

On Fri, 24 Nov 2017, RHAIEM, Mohamed Slim via curl-library wrote:

> < HTTP/1.1 503 Service Unavailable

You didn't tell us what you do to get this, so the only thing we can talk
about is HTTP response code 503. It is documentedin RFC 7231 section 6.6.4 and
says:

    The 503 (Service Unavailable) status code indicates that the server
    is currently unable to handle the request due to a temporary overload
    or scheduled maintenance, which will likely be alleviated after some
    delay. The server MAY send a Retry-After header field
    (Section 7.1.3) to suggest an appropriate amount of time for the
    client to wait before retrying the request.

Like all 5xx codes, the "fault" here is in the server. It is not caused by the
client - assuming it returns a correct response code.

-- 
  / daniel.haxx.se
-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette:   https://curl.haxx.se/mail/etiquette.html
Received on 2017-11-24