18,363
社区成员




CString CHttpClient::doPost(CString href)
{
CString httpsource="";
CInternetSession session1;
CHttpConnection* conn1=NULL;
CHttpFile* pFile = NULL;
CString strServerName;
CString strObject;
INTERNET_PORT nPort;
DWORD dwServiceType;
AfxParseURL((LPCTSTR)href,dwServiceType, strServerName, strObject, nPort);
DWORD retcode;
char* outBuff = CONTENT.GetBuffer(1000);
try
{
conn1 = session1.GetHttpConnection(strServerName,nPort);
pFile = conn1->OpenRequest(0,strObject,NULL,1,NULL,"HTTP/1.1",INTERNET_FLAG_EXISTING_CONNECT|INTERNET_FLAG_NO_AUTO_REDIRECT);
pFile -> AddRequestHeaders("Content-Type: application/x-www-form-urlencoded");
pFile -> AddRequestHeaders("Accept: */*");
pFile -> SendRequest(NULL,0,outBuff,strlen(outBuff)+1); //=====同样的网络环境同样是win7x64位有的电脑运行正常 有的电脑运行到这句后出错继续不了 catch也没用直接内存异常
pFile -> QueryInfoStatusCode(retcode);
}
catch (CInternetException * e){};
if(pFile)
{
CString text;
for(int i=0;pFile->ReadString(text);i++)
{
//httpsource=httpsource+text+"/r/n";
httpsource=httpsource+text;
}
pFile->Close();
}else
{
}
return httpsource;
delete pFile;
delete conn1;
session1.Close();
}
OutputDebugString(outBuff);
buff没有问题,打印出来正常的
这个代码百度搜索vc post都可以搜索到好多份
我在想既然大家都在用为什么就我出问题???
而且我也不是全部电脑出问题,只是部分电脑(目前就发现三台这样的)
我郁闷了