LPSTR HttpRequest::Post( LPSTR path,LPSTR args )
{ SendFormat("POST %s HTTP/1.1",path);
SendFormat("Host: %s",m_hostName);
SendFormat("User-Agent: %s","Kutu/1.0 (Windows)");
connection->SendLine("Keep-Alive: 115");
connection->SendLine("Connection: keep-alive");
connection->SendLine("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
connection->SendLine("Accept-Language: zh-cn,zh;q=0.5");
connection->SendLine("Accept-Charset: utf-8;q=0.7,*;q=0.7");
connection->SendLine("Content-Type: application/x-www-form-urlencoded");
CHAR dataLen[6];
sprintf(dataLen,"%d",strlen(args));
connection->Send("Content-Length: ");
connection->SendLine(dataLen);
connection->SendLine("");
connection->Send(args);
char *tmpBuffer = new char[1024];
char * defMem;
char * prevMem;
defMem=prevMem=NULL;
ULONG totalSize=0;
int curSize=0;
int preSize = 0;
while((curSize=connection->Receive(tmpBuffer))!=0){ totalSize += curSize;
defMem=(char*)VirtualAlloc(NULL,totalSize,MEM_COMMIT,PAGE_READWRITE); if(prevMem!=NULL){
CopyMemory(defMem,prevMem,preSize); VirtualFree(prevMem,preSize,MEM_DECOMMIT);
}
CopyMemory(defMem+preSize,tmpBuffer,curSize);
preSize += curSize;
prevMem = defMem;
} delete []tmpBuffer;
tmpBuffer = NULL; int len=MultiByteToWideChar(CP_UTF8, 0, defMem, -1, NULL,0);
unsigned short* wszGBK = new unsigned short[len+1];
memset(wszGBK, 0, len * 2 + 2);
MultiByteToWideChar(CP_UTF8, 0,defMem, -1, (LPWSTR)wszGBK, len);
len = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)wszGBK, -1, NULL, 0, NULL, NULL);
char *szGBK=new char[len+1];
memset(szGBK, 0, len+1);
WideCharToMultiByte (CP_ACP, 0, (LPCWSTR)wszGBK, -1, (LPSTR)szGBK, len, NULL,NULL);
VirtualFree(defMem,totalSize,MEM_DECOMMIT);
delete []wszGBK;
wszGBK = NULL;
return szGBK;
}
HttpRequest* request = new HttpRequest("127.0.0.1:1432");
char* result = request->Post("/WebSite3/Default.aspx","测试");
request->Close();
delete result;<----------报错 无法删除该字符串
delete request;
{ SendFormat("POST %s HTTP/1.1",path);
SendFormat("Host: %s",m_hostName);
SendFormat("User-Agent: %s","Kutu/1.0 (Windows)");
connection->SendLine("Keep-Alive: 115");
connection->SendLine("Connection: keep-alive");
connection->SendLine("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
connection->SendLine("Accept-Language: zh-cn,zh;q=0.5");
connection->SendLine("Accept-Charset: utf-8;q=0.7,*;q=0.7");
connection->SendLine("Content-Type: application/x-www-form-urlencoded");
CHAR dataLen[6];
sprintf(dataLen,"%d",strlen(args));
connection->Send("Content-Length: ");
connection->SendLine(dataLen);
connection->SendLine("");
connection->Send(args);
char *tmpBuffer = new char[1024];
char * defMem;
char * prevMem;
defMem=prevMem=NULL;
ULONG totalSize=0;
int curSize=0;
int preSize = 0;
while((curSize=connection->Receive(tmpBuffer))!=0){ totalSize += curSize;
defMem=(char*)VirtualAlloc(NULL,totalSize,MEM_COMMIT,PAGE_READWRITE); if(prevMem!=NULL){
CopyMemory(defMem,prevMem,preSize); VirtualFree(prevMem,preSize,MEM_DECOMMIT);
}
CopyMemory(defMem+preSize,tmpBuffer,curSize);
preSize += curSize;
prevMem = defMem;
} delete []tmpBuffer;
tmpBuffer = NULL; int len=MultiByteToWideChar(CP_UTF8, 0, defMem, -1, NULL,0);
unsigned short* wszGBK = new unsigned short[len+1];
memset(wszGBK, 0, len * 2 + 2);
MultiByteToWideChar(CP_UTF8, 0,defMem, -1, (LPWSTR)wszGBK, len);
len = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)wszGBK, -1, NULL, 0, NULL, NULL);
char *szGBK=new char[len+1];
memset(szGBK, 0, len+1);
WideCharToMultiByte (CP_ACP, 0, (LPCWSTR)wszGBK, -1, (LPSTR)szGBK, len, NULL,NULL);
VirtualFree(defMem,totalSize,MEM_DECOMMIT);
delete []wszGBK;
wszGBK = NULL;
return szGBK;
}
HttpRequest* request = new HttpRequest("127.0.0.1:1432");
char* result = request->Post("/WebSite3/Default.aspx","测试");
request->Close();
delete result;<----------报错 无法删除该字符串
delete request;
解决方案 »
- 散分: 如果要卸载, 360和qq你选择哪一个???
- 举报倒分
- CRichEditView类中创建动态控件后无法输入
- 各位同仁.请问怎样才算精通VC++啊,
- 如何给另一个程序发送消息
- 用VC60如何生成DLL文件?
- 不可思议的驱动程序,居然装完网卡驱动后不需要重启pc!居然能立刻生效
- 当我点File\open以后,那个选择文件的对话框,程序是是用什么函数让他出现的的?
- 又混淆了:LPCWSTR, TCHAR, LPCTSTR, LPSTR, LPWSTR...
- 几个windows系统问题,欢迎回答并参加讨论
- VC2008创建的安装程序没有卸载的项?
- 怎样根据已知的直线绘制与之相互垂直的直线呢?求大侠们赐教
试一下