I am trying to parse the following URL using the cURL library:
www.ncbi.nlm.nih.gov/nucleotide/? term = Anthoxanthum[organism] AND 2003/7/25:2005/12/27[Publication Date]&format=text
but cURL returns xml (the default, not text I've asked for).
I'm using this code line: curl_easy_setopt(curl, CURLOPT_URL, URL.c_str());
Here's the wierd thing: when I replace the "URL.c_str()" above with the actual text of the web search I want to do, it works fine. Also, if I paste in the URL from fout<<URL, that works fine in a browser.
Seems to me it's a c_str() problem, maybe the "&" or "="? but I can't figure it out, so I turn to the cplusplus forum for their usual wisdom.
The URL works fine (pasted into browser), also works fine if I output the string to a text file and paste that.
The returned cURL data is in the desired text form when I explicitly define the URL: curl_easy_setopt(curl, CURLOPT_URL, "www.ncbi.nlm.nih.gov/nucleotide/? term = Anthoxanthum[organism] AND 2003/7/25:2005/12/27[Publication Date]&format=text")
but if I say:
1 2 3
URL= "www.ncbi.nlm.nih.gov/nucleotide/? term = Anthoxanthum[organism] AND
curl_easy_setopt(curl, CURLOPT_URL, URL.c_str());
Is the string URL still in scope when you call curl_easy_perform (or whatever)??
(A string literal is stored in the const segment of your exe, so it will never be deallocated. But a string will be destroyed as soon as it goes out of scope, invalidating the (const) char* returned by c_str().)
PS Not directly related to the c_str()/char* problem, but the documention for CURLOPT_URL does say you should specify the scheme (e.g. http://, ftp:://, ldap://, ...) as part of the URL.
Pass in a pointer to the actual URL to deal with. The parameter should be a char * to a zero terminated string which must be URL-encoded in the following format:
The webpage I'm trying to access is just straight-up old fashioned text. I don't think it's a java issue, because I go the first request to work, but this one won't work even if I explicitly encode the url.
do you know how I can check the URL "sent" by libcurl?