Using my code to set the url option?

51 views
Skip to first unread message

nvangogh

unread,
Mar 17, 2013, 3:34:59 PM3/17/13
to cur...@googlegroups.com
Hello,
In the examples the url option always seems to be hard coded into the programs. I am seeking to set the url option depending upon selections made by the user at the command line. This is probably easily done, but I am new to using libcurl and curlpp and cannot figure out how to do it. So for example:

#include <iostream>
#include <string>
#include <curlpp/cURLpp.hpp>
#include <curlpp/Easy.hpp>
#include <curlpp/Options.hpp>

int main()
{
  // code selection of a url
  cURLpp::Cleanup mycleanup;
  int option;
  curlpp::options::Url myurl;
  std::cout << "Input option '1' for uk or option '2' for us \n";
  std::cin >> option;
  switch(option)
    {
    case 1:
      std::cout << "Option 1 selected...\n";
      myurl = "http://www.uk.co.uk";
      break;
    case 2:
      std::cout << "Option 2 selected...\n";
      myurl = "http://www.us.com";
      break;
    }
  
  
  return 0;
}

This code does not compile but i am trying to achieve something similar to this with my code. 

As an alternative to help explain my problem, consider this:

curlpp::options::Url myurl(std::string("https://www.google.com"));

Now if that was the url i wanted to use all the time - that would be fine. But depending upon selection of an option in my code, i might want to set the target url to "http:www.lycos.com" or perhaps "http://www.yahoo.com". In other words, the target url only becomes known at runtime and is dependant upon a user selection at the command line.

From what I can understand, the documentation appears to say that url takes the following argument (const char *link) - so can what i seek be achieved with a pointer or reference to a string? I would appreciate a snippet of code if you are able to help with this.
 
thanks

ranjeet kumar

unread,
Mar 18, 2013, 1:50:24 AM3/18/13
to cur...@googlegroups.com
You can put variable "url". Either you can put it from any command line or call from some other function or define some constant in header file.
For example:
 
int querySend(CString csURL)
{
 
       int cucRetCode;
      
     curl_easy_init();
 
    curl_easy_setopt(cuhpCurlHandle,CURLOPT_URL,csURL) ;
 
     cucRetCode = curl_easy_perform(cuhpCurlHandle);
 
    return cucRetCode;
}
--
You received this message because you are subscribed to the Google Groups "curlpp" group.
To unsubscribe from this group and stop receiving emails from it, send an email to curlpp+un...@googlegroups.com.
To post to this group, send email to cur...@googlegroups.com.
Visit this group at http://groups.google.com/group/curlpp?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply all
Reply to author
Forward
0 new messages