cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: CURLE_OPT_MALFORMAT question regarding CURLcode retval = curl_easy_setopt(m_curl_handle, CURLOPT_URL, (char*)m_sUrl.c_str())

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Sat, 1 Aug 2015 23:53:38 +0200 (CEST)

On Fri, 31 Jul 2015, Frank Chang wrote:

> I am curious why Alternative #2 returns CURLE_OPT_MALFORMAT when I do a
> curl_easy_perform(m_curl);

> /* In Alternative #2, m_strUrl is a C++ std::string member variable */
> CURLcode retval =
> curl_easy_setopt(m_curl_handle, CURLOPT_URL, (char *)m_sUrl.c_str());
> CURLcode perform = curl_easy_perform(m_curl);

Output what the string looks like (immediately before curl_easy_perform), show
it to us and we might be able to help and understand better:

  printf("%s\n", m_sUrl.c_str());

> I am wondering why Alternative #2 chokes when I do : CURLcode retval =
> curl_easy_setopt(m_curl_handle, CURLOPT_URL, (char*)m_sUrl.c_str()); Is it
> necessary that I create a writable copy

Nope. libcurl doesn't write to the data it gets a pointer to.

-- 
  / daniel.haxx.se
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html
Received on 2015-08-01