纯C++实现的HTTP请求(POST/GET),支持windows和linux,
进行简单的封装, 方便调用。实现如下:
#include "HttpConnect.h"
#ifdef WIN32
#pragma comment(lib,"ws2_32.lib")
#endif
HttpConnect::HttpConnect()
{
#ifdef WIN32
//此处一定要初始化一下,否则gethostbyname返回一直为空
WSADATA wsa = { 0 };
WSAStartup(MAKEWORD(2, 2), &wsa);
#endif
}
HttpConnect::~HttpConnect()
{
}
void HttpConnect::socketHttp(std::string host, std::string request)
{
int sockfd;
struct sockaddr_in address;
struct hostent *server;
sockfd = socket(AF_INET,SOCK_STREAM,0);
address.sin_family &