C++使用http请求,亲测可用,VS2008编译运行通过

int CMyFunctionsDlg::request(char* hostname, char* api, char* parameters)
{
    WSADATA WsaData;
    WSAStartup(0x0101, &WsaData);


    //初始化socket
    struct hostent* host_addr = gethostbyname(hostname);
    if (host_addr == NULL)
    {
//		cout<<"Unable to locate host"<h_addr_list);


    int sock = socket(AF_INET, SOCK_STREAM, 0);
    if (sock == -1)
    {
        return -100;
    }


    //建立连接
    if (connect(sock, (const struct sockaddr *)&sin, sizeof(sockaddr_in) ) == -1)
    {
//        cout<<"connect failed"<



request("www.xxxx.com", "http://www.xxxx.com/client/data.php", "{\"request\":\"userLogin\",\"posts\":[{\"loginName\":\"123456\",\"password\":\"7890\"}]}");

你可能感兴趣的:(C++使用http请求,亲测可用,VS2008编译运行通过)