Asked  6 Months ago    Answers:  5   Viewed   40 times

Is there any way to easily make a HTTP request with C++? Specifically, I want to download the contents of a page (an API) and check the contents to see if it contains a 1 or a 0. Is it also possible to download the contents into a string?

 Answers

55

I had the same problem. libcurl is really complete. There is a C++ wrapper curlpp that might interest you as you ask for a C++ library. neon is another interesting C library that also support WebDAV.

curlpp seems natural if you use C++. There are many examples provided in the source distribution. To get the content of an URL you do something like that (extracted from examples) :

// Edit : rewritten for cURLpp 0.7.3
// Note : namespace changed, was cURLpp in 0.7.2 ...

#include <curlpp/cURLpp.hpp>
#include <curlpp/Options.hpp>

// RAII cleanup

curlpp::Cleanup myCleanup;

// Send request and get a result.
// Here I use a shortcut to get it in a string stream ...

std::ostringstream os;
os << curlpp::options::Url(std::string("http://www.wikipedia.org"));

string asAskedInQuestion = os.str();

See the examples directory in curlpp source distribution, there is a lot of more complex cases, as well as a simple complete minimal one using curlpp.

my 2 cents ...

Tuesday, June 1, 2021
 
StampyCode
answered 6 Months ago
59
#include <windows.h>

Sleep(number of milliseconds);

Or if you want to pause your program while waiting for another program, use WaitForSingleObject.

Monday, August 2, 2021
 
Claudio
answered 4 Months ago
30

HttpRequest is present on the Page and UserControl classes as a GET-only property. Similarly, most of its own properties are also GET-only (see 1). This class is used by ASP.NET pages to get information about the incoming http request, e.g. read the client IP, cookies, the query string, whatnot. Importantly, it is part of the "Old" System.Web assembly, which has been around since .NET 1.1

HttpRequestMessage, on the other hand, is new in .NET 4.5. It is part of System.Net. It can be used both by clients and services to create, send and receive requests and responses over HTTP. It replaces HttpWebRequest, which is obsolete in .NET 4.5

On HttpRequestBase and HttpRequestWrapper, best I can do is to just quote the docs

The HttpRequestWrapper class derives from the HttpRequestBase class and serves as a wrapper for the HttpRequest class. This class exposes the functionality of the HttpRequest class and exposes the HttpRequestBase type. The HttpRequestBase class enables you to replace the original implementation of the HttpRequest class in your application with a custom implementation, such as when you perform unit testing outside the ASP.NET pipeline.

Monday, September 6, 2021
 
Pradip
answered 3 Months ago
74

Source: How to determine browser type in server-side code without the BrowserType object in ASP.NET

In ASP.NET, you can access the Request.ServerVariables collection or use the new Request.UserAgent property to retrieve the HTTP_USER_AGENT header value.

There are no difference, both will retrieve same thing HTTP_USER_AGENT header value.

Check Request.ServerVariables Collection and IIS Server Variables if you want to dig it in deep. These server variables collection values somewhat depend ond the IIS version also.

Tuesday, November 9, 2021
 
mplappert
answered 3 Weeks ago
87

Turned out to be fairly straight forward, but still wondering if there's a more accepted way of doing a HEAD.

S3GetObjectRequest *headRequest = [[[S3GetObjectRequest alloc] initWithKey:keyname withBucket: [bucketname]] autorelease];
headRequest.httpMethod = @"HEAD";

S3Response *headResponse = [[S3Response alloc] init];
headResponse = [self.awsConnection invoke:headRequest];
Wednesday, November 24, 2021
 
Ahmed Haque
answered 5 Days ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 
Share