多谢各位大侠了,
前提是给出一个url

解决方案 »

  1.   

    vc中有这样的类函数,但估计在linux下不能用如果不能下载网页,实现对网页的连接也是可以的
      

  2.   

    标准C++里没有,只能找第3方库,wxWindows里好象有这类API
      

  3.   

    感谢楼上的回答,但我想在linux环境下实现,请问linux环境下有没有编译器提供此类函数啊?
    另外,wxwindows是什么东西啊,是不是肯定不能用于linux环境下
      

  4.   

    wxWindows是一个跨平台的GUI库,可以在Linux下运行。官方网站www.wxwindows.org/www.wxwidgets.org,不过国内要用代理才能上去
      

  5.   

    wxWindows是跨平台得C++ GUI库。
    Linux平台没有封装这样得函数,不过完全可以写程序自己实现。。
      

  6.   

    也是~楼主可以组织一个开源项目,实现一套跟HTTP服务器通信的库。
      

  7.   

    楼主你知道http协议吗?
    不知道
    那就去看~~~
      

  8.   

    还要问一句,各位说的在linux下是不是就是无法使用wxWindows了
    但能不能用kdevelop提供的库阿。
    另外要是自己编写,各位大侠各个思路(怎么利用合http协议发送get,或者head命令)
      

  9.   

    用C++干这个比较累的说,用perl之类的脚本加个module轻松搞定
      

  10.   

    纯c++也就是标准的c++,那东西必须调用操作系统的功能才能完成,要在纯C++下写这种代码,那是不可能的,除非自己写一个HTTP协议库存.
      

  11.   

    自己实现也是可能的, 如果只是要下载http服务器上的内容而已telnet到80端口, 然后用get
      

  12.   

    只是把网页上的源代码下载下来,
    请问用telnet怎么具体的实现阿
      

  13.   

    //
    // GetHTTP3.cpp -- Retrieve a file from a HTTP server
    //
    // This version uses overlapped I/O
    // with a completion function.
    //
    // Compile and link with ws2_32.lib
    //#include <fcntl.h>
    #include <io.h>
    #include <stdio.h>
    #include <winsock2.h>#pragma comment(lib, "ws2_32.lib")void GetHTTP(LPCSTR lpServerName, LPCSTR lpFileName);//
    // Overlapped I/O completion function
    //
    void CALLBACK RecvComplete(DWORD dwError, 
       DWORD cbTransferred, 
       LPWSAOVERLAPPED lpOverlapped, 
       DWORD dwFlags); // Helper macro for displaying errors
    #define PRINTERROR(s) fprintf(stderr,"\n%s %d\n", s, WSAGetLastError())#define BUFFER_SIZE 1024//
    // Structure used to pass
    // additional info to the 
    // completion function
    //
    typedef struct tagIOREQUEST
    {
    WSAOVERLAPPED over; // Must be first
    SOCKET Socket;
    BOOL fFinished;
    LPBYTE pBuffer;
    }IOREQUEST, *LPIOREQUEST;
    void main(int argc, char **argv)
    {
    WORD wVersionRequested = WINSOCK_VERSION;
    WSADATA wsaData;
    int nRet; //
    // Check arguments
    //
    if (argc != 3)
    {
    fprintf(stderr,
    "\nSyntax: GetHTTP ServerName FullPathName\n");
    return;
    } //
    // Initialize WinSock.dll
    //
    nRet = WSAStartup(wVersionRequested, &wsaData);
    if (nRet)
    {
    fprintf(stderr, "\nWSAStartup() error (%d)\n", 
    nRet);
    WSACleanup();
    return;
    } //
    // Check WinSock version
    //
    if (wsaData.wVersion != wVersionRequested)
    {
    fprintf(stderr,"\nWinSock version not supported\n");
    WSACleanup();
    return;
    } //
    // Set "stdout" to binary mode
    // so that redirection will work
    // for binary files (.gif, .jpg, .exe, etc.)
    //
    setmode(_fileno(stdout), _O_BINARY); //
    // Call GetHTTP() to do all the work
    //
    GetHTTP(argv[1], argv[2]); WSACleanup();
    }
    void GetHTTP(LPCSTR lpServerName, LPCSTR lpFileName)
    {
    LPHOSTENT lpHostEntry;
    SOCKADDR_IN saServer;
    SOCKET Socket;
    int nRet; //
    // Lookup the host address
    //
    lpHostEntry = gethostbyname(lpServerName);
    if (lpHostEntry == NULL)
    {
    PRINTERROR("socket()");
    return;
    }

    // Create a TCP/IP stream socket
    Socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
    if (Socket == INVALID_SOCKET)
    {
    PRINTERROR("socket()");
    return;
    } //
    // Fill in the rest of the server address structure
    //
    saServer.sin_family = AF_INET;
    saServer.sin_addr = *((LPIN_ADDR)*lpHostEntry->h_addr_list);
    saServer.sin_port = htons(80); //
    // Connect the socket
    //
    nRet = connect(Socket, (LPSOCKADDR)&saServer, sizeof(SOCKADDR_IN));
    if (nRet == SOCKET_ERROR)
    {
    PRINTERROR("connect()");
    closesocket(Socket);
    return;
    }

    //
    // Format the HTTP request
    // and send it
    //
    char szBuffer[1024];
    sprintf(szBuffer, "GET %s\n", lpFileName);
    nRet = send(Socket, szBuffer, strlen(szBuffer), 0);
    if (nRet == SOCKET_ERROR)
    {
    PRINTERROR("send()");
    closesocket(Socket);
    return;
    } //
    // We're connected, so we can now
    // post a receive buffer
    // // 
    // We use a little trick here to pass additional
    // information to out completion function.
    // We append any additional info onto the end
    // of a WSAOVERLAPPED structure and pass it
    // as the lpOverlapped parameter to WSARecv()
    // When the completion function is called,
    // this additional info is then available.
    //
    BYTE aBuffer[BUFFER_SIZE];
    IOREQUEST ioRequest;
    memset(&ioRequest.over, 0, sizeof(WSAOVERLAPPED));
    ioRequest.Socket = Socket;
    ioRequest.fFinished = FALSE;
    ioRequest.pBuffer = aBuffer; WSABUF wsabuf;
    wsabuf.len = BUFFER_SIZE;
    wsabuf.buf = (char *)aBuffer; DWORD dwRecv;
    DWORD dwFlags = 0;
    nRet = WSARecv(Socket, 
       &wsabuf,
       1,
       &dwRecv,
       &dwFlags,
       (LPWSAOVERLAPPED)&ioRequest,
       RecvComplete);
    if (nRet == SOCKET_ERROR)
    {
    if (WSAGetLastError() != WSA_IO_PENDING)
    {
    PRINTERROR("WSARecv()");
    closesocket(Socket);
    return;
    }
    } // Receive the file contents and print to stdout
    while(1)
    {
    //
    // We could do other processing here
    // //
    // Use the SleepEx() function to signal
    // that we are in an altertable wait state
    //
    SleepEx(0, TRUE); //
    // If the completion function says we're finished
    //
    if (ioRequest.fFinished)
    break;
    }
    closesocket(Socket);
    }void CALLBACK RecvComplete(DWORD dwError, 
       DWORD cbRecv, 
       LPWSAOVERLAPPED lpOver, 
       DWORD dwFlags)
    {
    //
    // Check for errors
    //
    if (dwError)
    {
    fprintf(stderr,"\nRecvComplete() error: %ld", 
    dwError);
    return;
    } LPIOREQUEST pReq = (LPIOREQUEST)lpOver; //
    // If no error and no data returned,
    // then the connection has been closed.
    //
    if (cbRecv == 0)
    {
    pReq->fFinished = TRUE;
    return;
    } fprintf(stderr,"\nRecvComplete(): %ld bytes received", cbRecv);
    //
    // Write the received data to stdout
    //
    fwrite(pReq->pBuffer, cbRecv, 1, stdout); // 
    // And then post the buffer to receive again
    //
    WSABUF wsabuf;
    wsabuf.len = BUFFER_SIZE;
    wsabuf.buf = (char *)pReq->pBuffer; DWORD dwRecv;
    dwFlags = 0;
    int nRet;
    nRet = WSARecv(pReq->Socket, 
       &wsabuf,
       1,
       &dwRecv,
       &dwFlags,
       lpOver,
       RecvComplete);
    if (nRet == SOCKET_ERROR)
    {
    if (WSAGetLastError() != WSA_IO_PENDING)
    {
    PRINTERROR("RePost with WSARecv()");
    pReq->fFinished = TRUE;
    }
    }
    }
      

  14.   

    纯的C++?有难度吧?在VC里有现成的可以用啊?
      

  15.   

    回复人: ToIP(朽木) 
    ========================================================================我很想知道你的这个程序确实能下载到网页????????
    请问你试过没有?
      

  16.   

    不知道哪位朋友有兴趣把    回复人: ToIP(朽木)  的代码测试一下,我很想知道结果我在网吧,没有办法测试
      

  17.   

    答案是“不可能”,因为你要“纯C++”,纯C++哪来的网络操作函数呢?要进行网络操作,只能用操作系统提供的API。
    如果允许使用socket的话,那么可以用tcp与目标机器连接,并向80端口发送一段GET请求,对方就会将网页传回来了。