Hi!

I'm trying to implement the easy curl function to get a website, curl_easy_setopt(curl, CURLOPT_URL, m_sURL);, where the third argument is the only one that i give, and it's in this part of the code:

...
public:
    string m_sURL;
    URL() : m_sURL("http://www.google.com") {   }
    ...

Now, when I call curl_easy_setopt(curl, CURLOPT_URL, "http://www.google.com"); everything works fine. But if instead, I want to dynamically submit my own URL with m_sURL like this: curl_easy_setopt(curl, CURLOPT_URL, m_sURL);, doesn't work.

I'm using cout << endl << "Usando: " << m_sURL << endl; right before calling curl_easy_setopt... and it looks like it's what it should be, but cURL says it can't resolve the hostname. So there must be some hidden character I can't see in m_sURL?

Thanks.

A string is not exactly the same as a character array. There's a bit of overhead that goes into it.
Try using

 curl_easy_setopt(curl, CURLOPT_URL, m_sURL.c_str());

It works now with c_str().

Why exactly wasn't working before?

Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.