简体   繁体   中英

open url mac osx c++

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++.

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.

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM