18,356
社区成员
发帖
与我相关
我的任务
分享
strTemp.Format(_T("guid=%s&title=iiiiiiii&linkman=llllllllll&telephone=ttttt&address=aaaaaa&wcpip=ccccc&wfpip=ffffff"),m_strGUID);
//HINSTANCE hs = ShellExecute(NULL,_T("open"),strTemp,NULL,NULL,SW_HIDE);
try
{
CString strServerName;
CString strObject;
INTERNET_PORT nPort;
DWORD dwServiceType;
if(!AfxParseURL((LPCTSTR)m_strWebService, dwServiceType, strServerName, strObject, nPort))
{
MessageBox(_T("不是有效的网络地址!"));
return;
}
CString strFormData = strTemp;
CInternetSession session;
CHttpConnection* pConnection = session.GetHttpConnection(strServerName,nPort);//_T("192.168.1.216"),(INTERNET_PORT)80);
if (pConnection==NULL)
{
MessageBox(_T("连接失败!"));
return;
}
CHttpFile* pFile = pConnection->OpenRequest(CHttpConnection::HTTP_VERB_POST,strObject,NULL,1,NULL,_T("HTTP/1.1"),INTERNET_FLAG_EXISTING_CONNECT|INTERNET_FLAG_NO_AUTO_REDIRECT);//_T("/wcp1/webservices/admin/unitwebservice.asmx/SaveUnit"));
if (pFile==NULL)
{
MessageBox(_T("找不到网络地址!"));
return;
}
CString strHeaders = _T("Content-Type: application/x-www-form-urlencoded");
pFile->AddRequestHeaders(strHeaders);
BOOL result = pFile->SendRequest(strHeaders,(LPVOID)(LPCTSTR)strFormData, strFormData.GetLength());
DWORD dwRet;
pFile->QueryInfoStatusCode(dwRet);
if(dwRet != HTTP_STATUS_OK)
{
CString errText;
errText.Format(_T("POST出错,错误码:%d"), dwRet);
AfxMessageBox(errText);
}