该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
CString CHttpClient::doPost(CString href)
{
CString httpsource="";
CInternetSession session1;
CHttpConnection* conn1=NULL;
CHttpFile* pFile = NULL;
CString strServerName;
CString strObject;
INTERNET_PORT nPort;
DWORD dwServiceType;
CString sasd("sasdasda");
if(AfxParseURL((LPCTSTR)href,dwServiceType, strServerName, strObject, nPort) == 0)
{
AfxMessageBox("URL不正确");
}
DWORD retcode;
char* outBuff = CONTENT.GetBuffer(0);
try
{
conn1 = session1.GetHttpConnection(strServerName,nPort);
if(conn1 == NULL)
{
AfxMessageBox("对不起,连接服务器失败!");
}
pFile = conn1->OpenRequest(0,strObject,NULL,1,NULL,"HTTP/1.0",INTERNET_FLAG_EXISTING_CONNECT|INTERNET_FLAG_NO_AUTO_REDIRECT);
if(pFile == NULL)
{
AfxMessageBox("找不到网络地址");
}
//pFile -> AddRequestHeaders("Content-Type: application/x-www-form-urlencoded");
//pFile -> AddRequestHeaders("Content-Type:application/json;charset=utf-8");
pFile -> AddRequestHeaders("Content-Type: application/x-www-form-urlencoded; charset=UTF-8");
pFile -> AddRequestHeaders("Accept: */*");
pFile -> SendRequest(NULL,0,outBuff,strlen(outBuff)+1);
pFile -> QueryInfoStatusCode(retcode);
}
catch (CInternetException * e)
{
char ErrMS[3000]="";
e->GetErrorMessage(ErrMS,3000);int Code = GetLastError();
};
if(pFile)
{
CString text("");
for(int i=0;pFile->ReadString(text);i++)
{
httpsource=httpsource+text+"\r\n";
}
pFile->Close();
}
else
{
}
delete pFile;
delete conn1;
session1.Close();
return httpsource;
}