HTTP client example on win32

2020-05-20 09:15发布

I wanted to develop one HTTP example on win32 platform, which is asynchronous.

I am new to win32 programming, what are the api and library win32 platform provides for HTTP send and receive request? I am using Windows XP with VS 2005.

If any example is available please provide a link to it.

5条回答
祖国的老花朵
2楼-- · 2020-05-20 09:47

You can use WinHTTP library. Here is an sample on Asynchronous completion.

查看更多
The star\"
3楼-- · 2020-05-20 09:54

Generally I'd recommend something cross-platform like cURL, POCO, Qt, or Asio (pretty modern and nice). However, here is a Windows example using IXMLHTTPRequest:

// TODO: error handling

#include <atlbase.h>
#include <msxml6.h>

HRESULT hr;
CComPtr<IXMLHTTPRequest> request;

hr = request.CoCreateInstance(CLSID_XMLHTTP60);
hr = request->open(
    _bstr_t("GET"),
    _bstr_t("https://www.google.com/images/srpr/logo11w.png"),
    _variant_t(VARIANT_FALSE),
    _variant_t(),
    _variant_t());
hr = request->send(_variant_t());

// get status - 200 if succuss
long status;
hr = request->get_status(&status);

// load image data (if url points to an image)
VARIANT responseVariant;
hr = request->get_responseStream(&responseVariant);
IStream* stream = (IStream*)responseVariant.punkVal;
CImage image = new CImage();
image->Load(stream);
stream->Release();
查看更多
\"骚年 ilove
4楼-- · 2020-05-20 09:59

Boost Asio is a nice synchronous/asynchronous library which has everything you need for HTTP servers/clients. It has some extensive examples on HTTP servers, and the relevant clients. Now if you are new to C++ in general this library may be a little cryptic. You could always go have a look at MSDN if you want a more from scratch approach.

查看更多
贼婆χ
5楼-- · 2020-05-20 10:02

Window HTTP Services "provides developers with an HTTP client application programming interface (API) to send requests through the HTTP protocol to other HTTP servers."

HTTP Server API "enables applications to communicate over HTTP without using Microsoft Internet Information Server (IIS)"

查看更多
Juvenile、少年°
6楼-- · 2020-05-20 10:02

This is an example

https://github.com/pedro-vicente/lib_netsockets

A C++ light wrapper for POSIX and Winsock sockets

It uses HTTP GET to retrieve a file from a web server, both server and file are command line parameters. The remote file is saved to a local copy.

查看更多
登录 后发表回答