m_Sock.Init();
m_Sock.Create(3520);//创建本机套接字
bool bRet = m_Sock.Connect("218.58.188.194" , 80);//连接服务器IP端口我现在已经连接到了服务器的80端口,但接下来如何向服务器发送一个下载请求????????

解决方案 »

  1.   

    用WinHttp等api来发送http请求来下载等
      

  2.   

    CInternetSession httpsession; //定义网络连接Session
    CString Line;
    CInternetFile* webfile=NULL; //定义一个文件对象指针
    UpdateData();
    if(m_Url.Left(7)!="http://") //如果地址不含HTTP类型标志则添加本地文件类型标志
    {
    m_Url="http://"+m_Url;
    }
    try
    {
    webfile=(CInternetFile*)httpsession.OpenURL(m_Url);//打开连接
    }
    catch(CInternetException*pException) //捕捉异常
    {
    webfile=NULL;
    pException->Delete();
    }
    if(webfile)
    {
    //读出文件前一部分,这里如果文件多于80行,这里只显示前80行
    int i=0;
    while(webfile->ReadString(Line)&&i<80)
    {
    m_Text=m_Text+Line+"\r\n"; //加入换行标志
    i++;
    }
    }

    delete webfile; //删除
    httpsession.Close(); //关闭连接
      

  3.   

    楼上是基于MFC吧,,我这里要用SDK做...已经连接上服务器了,,,现在只是不知道如何向服务器发送下载请求....
      

  4.   

    回楼上...服务器支持HTTP协议...发送什么命令请求下载??
      

  5.   

    下载嘛。。你这样发个字符串
    HTTP GET XXXURL
      

  6.   

    不过也要看你的服务器是什么下载? HTTP 还是自定义协议。
      

  7.   

    //发送如下http请求头,以\r\n表示换行,最后发送一个空行\r\n表示请求头结束.
    //下载的文件是Http://www.sina.com.cn/index.html
    GET /index.html HTTP/1.1
    Host:www.sina.com.cn
    Accept:*/*
    User-Agent:Mozilla/4.0 (compatible; MSIE 5.00; Windows 98)
    Connection:Keep-Alive