返回首页

我使用Windows 7和inet_ntop和inet_pton中存在的问题,这似乎是为Linux。我使用Windows?


#include "stdafx.h"

#include <iostream>

#include <string>

#include <sstream>

#include 

#include <winsock2.h>

 

#pragma comment( lib,"Advapi32.lib" ) //Reg

#pragma comment( lib, "ws2_32.lib" ) // linker must use this lib for sockets

using namespace std;

 

void BuildHeader(stringstream &hdr, const string &payload, const sockaddr_in *remoteServer)

{

    char buf[16] = { 0 };

    hdr << "POST /login.jsp HTTP/1.1\r\n";

    hdr << "Host: " << inet_ntop(AF_INET,

                                 (const void *)&remoteServer->sin_addr,

                                 buf,

                                 sizeof(buf)) << "\r\n";

    hdr << "Content-Length: " << payload.size() << "\r\n";

    hdr << "Content-Type: text/html; charset=ISO-8859-4\r\n\r\n";

}

 

int main(void)

{

    sockaddr_in sa;

    inet_pton(AF_INET, "127.0.0.1", &(sa.sin_addr));

    stringstream ss;

    BuildHeader(ss, "<payload></payload>", &sa);

 

    cout << ss.str();

    return 0;

}</winsock2.h></sstream></string></iostream>
:7766180 |会员

回答