本文整理汇总了C++中CHttpFile::SendRequestEx方法的典型用法代码示例。如果您正苦于以下问题:C++ CHttpFile::SendRequestEx方法的具体用法?C++ CHttpFile::SendRequestEx怎么用?C++ CHttpFile::SendRequestEx使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CHttpFile
的用法示例。
在下文中一共展示了CHttpFile::SendRequestEx方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OnBtnSendpost
void CHttpPostDlg::OnBtnSendpost()
{
CInternetSession m_InetSession(_T("session"),
0,
INTERNET_OPEN_TYPE_PRECONFIG,
NULL,
NULL,
INTERNET_FLAG_DONT_CACHE); //设置不缓冲
CHttpConnection* pServer = NULL;
CHttpFile* pFile = NULL;
CString strHtml = "";
CString ActionServer = _T("www.cqjg.gov.cn");
CString strRequest = _T("LicenseTxt=AG8091&VIN=LJDAAA21560205432"); //POST过去的数据
CString strHeaders = "Accept: text*/*\r\nContent-Type: application/x-www-form-urlencoded\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon;";
int nRead = 0;
try
{
INTERNET_PORT nPort = 80; //端口
pServer = m_InetSession.GetHttpConnection(ActionServer, nPort);
pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_POST,"/netcar/FindOne.aspx");
pFile->AddRequestHeaders(strHeaders);
pFile->SendRequestEx(strRequest.GetLength());
pFile->WriteString(strRequest); //重要-->m_Request 中有"name=aaa&name2=BBB&..."
pFile->EndRequest();
DWORD dwRet;
pFile->QueryInfoStatusCode(dwRet);
if (dwRet == HTTP_STATUS_OK)
{
CString strLine;
while ((nRead = pFile->ReadString(strLine))>0)
{
strHtml += strLine + "\n";;
}
}
int pos = strHtml.Find(_T("<li class=\"lithreeC\">"));
if(pos != -1)
{
CString Value = strHtml.Mid(pos,500);
CFile file("test.html",CFile::modeCreate|CFile::modeWrite);
file.WriteHuge(Value.GetBuffer(0),Value.GetLength());
file.Close();
//MessageBox(Value);
}
delete pFile;
delete pServer;
}
catch (CInternetException* e)
{
char strErrorBuf[255];
e->GetErrorMessage(strErrorBuf,255,NULL);
AfxMessageBox(strErrorBuf,MB_ICONINFORMATION);
}
// SendPost();
}
示例2: DoOpenURL
void CHttpClient::DoOpenURL( LPCTSTR lpszURL, DWORD dwHttpRequestFlags,
CString &strHeader, CString &strPostData,
CInternetSession *pSession,
CHttpConnection **ppServer, CHttpFile **ppFile,
PROGRESS_CALLBACK fnCallback, void * cookie )
{
CString strServerName;
CString strObject;
INTERNET_PORT nPort;
DWORD dwServiceType;
int nVerb = (strPostData.GetLength()>0 ? CHttpConnection::HTTP_VERB_POST : CHttpConnection::HTTP_VERB_GET);
if (!AfxParseURL(lpszURL, dwServiceType, strServerName, strObject, nPort) ||
dwServiceType != INTERNET_SERVICE_HTTP)
{
ThrowTearException( ERR_TEAR_URLFORMAT );
}
if( fnCallback )
fnCallback( PROG_HTTPCONNECTTING, 0, NULL, cookie );
CHttpConnection *pServer = pSession->GetHttpConnection(strServerName, dwHttpRequestFlags, nPort, m_strProxyUser, m_strProxyPasswd );
CHttpFile * pFile = pServer->OpenRequest(nVerb, strObject, NULL, 1, NULL, NULL, dwHttpRequestFlags);
pFile->AddRequestHeaders(strHeader, HTTP_ADDREQ_FLAG_COALESCE);
if( strPostData.GetLength() > 0 ) // post
{
try
{
pFile->SendRequestEx( DWORD(strPostData.GetLength()) );
pFile->WriteString(strPostData);
pFile->EndRequest();
}
catch( CInternetException *pp ) // HTTP_STATUS_BAD_METHOD
{
pp->Delete();
// close up the redirected site
pFile->Close();
delete pFile;
pFile = NULL;
pServer->Close();
delete pServer;
pServer = NULL;
pServer = pSession->GetHttpConnection(strServerName, dwHttpRequestFlags, nPort, m_strProxyUser, m_strProxyPasswd );
pFile = pServer->OpenRequest(nVerb, strObject, NULL, 1, NULL, NULL, dwHttpRequestFlags);
pFile->AddRequestHeaders(strHeader, HTTP_ADDREQ_FLAG_COALESCE);
pFile->SendRequestEx( DWORD(strPostData.GetLength()) );
pFile->WriteString(strPostData);
pFile->EndRequest();
}
}
else
{
pFile->SendRequest();
}
if( fnCallback )
fnCallback( PROG_REQUESTSENT, 0, NULL, cookie );
// Bad Post method
DWORD dwRet = 0;
pFile->QueryInfoStatusCode( dwRet );
// if access was denied, prompt the user for the password
if (dwRet == HTTP_STATUS_DENIED
|| dwRet == HTTP_STATUS_PROXY_AUTH_REQ )
{
DWORD dwPrompt;
dwPrompt = pFile->ErrorDlg(NULL, ERROR_INTERNET_INCORRECT_PASSWORD,
FLAGS_ERROR_UI_FILTER_FOR_ERRORS | FLAGS_ERROR_UI_FLAGS_GENERATE_DATA
| FLAGS_ERROR_UI_FLAGS_CHANGE_OPTIONS, NULL);
// if the user cancelled the dialog, bail out
if (dwPrompt != ERROR_INTERNET_FORCE_RETRY)
ThrowTearException( ERR_TEAR_CANCEL );
if( strPostData.GetLength() > 0 ) // post
{
try{
pFile->SendRequestEx( DWORD(strPostData.GetLength()) );
pFile->WriteString(strPostData);
pFile->EndRequest();
}
catch( CInternetException *pp ) // HTTP_STATUS_BAD_METHOD
{
pp->Delete();
pFile->SendRequestEx( DWORD(strPostData.GetLength()) );
pFile->WriteString(strPostData);
pFile->EndRequest();
}
}
else
{
pFile->SendRequest();
}
pFile->QueryInfoStatusCode(dwRet);
}
//.........这里部分代码省略.........