GET示例
#include <afxinet.h> #include <iostream> #include <vector> #ifdef _UNICODE #define COUT wcout #else #define COUT cout #endif using namespace std; int main() { CInternetSession session(TEXT("MfcHttp")); CHttpConnection *connection = session.GetHttpConnection(TEXT("example.com"), (INTERNET_PORT)80); CHttpFile *file = connection->OpenRequest(CHttpConnection::HTTP_VERB_GET, TEXT("")); try { file->SendRequest(); DWORD statusCode; file->QueryInfoStatusCode(statusCode); if (HTTP_STATUS_OK == statusCode) { CString contentLength; file->QueryInfo(HTTP_QUERY_CONTENT_LENGTH, contentLength); int fileSize = _ttoi(contentLength); vector<char> buffer(fileSize + 1); UINT numberOfBytesRead = file->Read(&buffer[0], fileSize); buffer[fileSize] = '