|
CString strHeaders = _T("Content-Type: application/x-www-form-urlencoded");//http协议
CString strFormData;
strFormData.Format("UserName=%s,circle) ;
CString serverName = _T("127.0.0.1"); //ip
INTERNET_PORT nPort = 8088; //端口号
CString formAction = _T("\\web\\Service.jsp");
CInternetSession session;
CHttpConnection* pConnection = session.GetHttpConnection(serverName,nPort);
CHttpFile* pFile = pConnection->OpenRequest(CHttpConnection::HTTP_VERB_POST, formAction);
//在服务器没有打开时可能会出现至命错误
BOOL result = pFile->SendRequest(strHeaders, (LPVOID)(LPCTSTR)strFormData, strFormData.GetLength()); //发送请求
CString strResult;
pFile->ReadString(strResult);
strResult.TrimLeft();
strResult.TrimRight();
return atoi(strResult);
此段代码在调用pFile->SendRequest(strHeaders, (LPVOID)(LPCTSTR)strFormData, strFormData.GetLength());时如果服务器没有开启会出现至命错误,向高手请教解决问题的方案,谢谢 |
|