依赖于前面的sock类库,
CConvert::IntToStr可以单独写一个好了.
//---------------------------------------------------------------------------
#include "http.h"
#include "sock.h"
#include "convert.h"
#pragma hdrstop
//---------------------------------------------------------------------------
#pragma package(smart_init)
bool HttpDownload(string url,string &body,const
string& post)
{
      body="";
      int pos=url.find ('/',8);
      if(pos==-1)
      {
             
return false;
      }
      string
host=url.substr(7,pos-7);
      string remotepath=url.substr
(pos,url.length ());
     
pos=host.find(':');
      int port=80;
      if(pos!=-1)
      {
             
port=atoi(host.substr(pos+1,host.length()).c_str());
             
if(port==0)
                 
port=80;
             
host=host.substr(0,pos);
      }
      Sock m_sock;
      if(!m_sock.Connect(host,port))
      {
             
return false;
      }
      string cmd;
   if(post=="")
   {
    cmd="GET "+remotepath+"
HTTP/1.0\r\nHost: "+host+"\r\n\r\n";
   }
   else
   {
    cmd="POST "+remotepath+"
HTTP/1.0\r\nHost:
"+host+"\r\nContent-Length:"+CConvert::IntToStr(post.length())+"\r\n\r\n"+post;
   }
     
m_sock.Send((char*)cmd.c_str(),cmd.length());
      char* buf=new char[65537];
      bool head=true;
      try
      {
             
int len=0;
             
do
             
{
                     
len=0;
                     
len=m_sock.Recv(buf,65536);
                     
if(len>0)
                     
{
                             
buf[len]='\0';
                             
if(head)
                             
{