How do I hit a url in C++, there are a ton of examples for Objective-C, but my application doesn't use objective-c and starts with main() and is all c/c++. I was using URLSimpleDownload but it isn't working anymore (returns -50). I don't want to open a webpage or browser, I simply need to hit a url from c/c++.
Asked
Active
Viewed 911 times
2 Answers
1
You can take several of those NSURL
examples you referred to, and just use the equivalent CFURL*
APIs. Note: CFURLRef
is an NSURL*
. So you just need to figure out the corresponding CFURL*
interface which an NSURL
-based implementation uses.
This relationship where a CF-type is an NS-type is named "toll-free bridged".
Note that not everything will map one-to-one, NS-APIs have a lot of conveniences/additions -- it's better to think of it as an abstraction layer above CF-APIs.

justin
- 104,054
- 14
- 179
- 226
-
I see there is a NSString stringWithContentsOfURL function that is exactly what I need, but there is no corresponding CFString function for it? – Rasterman Nov 06 '12 at 16:03
-
Create a cfdata intermediate – justin Nov 06 '12 at 23:45
0
You could try downloading and installing cURLpp (code from neuro's post):
// Edit : rewritten for cURLpp 0.7.3
// Note : namespace changed, was cURLpp in 0.7.2 ...
#include <curlpp/cURLpp.hpp>
#include <curlpp/Easy.hpp>
#include <curlpp/Options.hpp>
// RAII cleanup
curlpp::Cleanup myCleanup;
// standard request object.
curlpp::Easy myRequest;
// Set the URL.
myRequest.setOpt(new curlpp::options::Url(std::string("http://example.com")));
// Send request and get a result.
// By default the result goes to standard output.
// Here I use a shortcut to get it in a string stream ...
std::ostringstream os;
os << myRequest.perform();
string asAskedInQuestion = os.str();