本文整理汇总了C++中HttpSendRequest函数的典型用法代码示例。如果您正苦于以下问题:C++ HttpSendRequest函数的具体用法?C++ HttpSendRequest怎么用?C++ HttpSendRequest使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了HttpSendRequest函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: WWWFileBuffer
//download file from WWW in a buffer
bool WWWFileBuffer(char *host, char *path, char *outBuffer, int outBufferSize)
{
bool retval = false;
LPTSTR AcceptTypes[2] = { TEXT("*/*"), NULL };
DWORD dwSize = outBufferSize - 1, dwFlags = INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE;
HINTERNET opn = NULL, con = NULL, req = NULL;
opn = InternetOpen(TEXT("Evilzone.org"), INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
if (!opn)
return retval;
con = InternetConnect(opn, host, INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
if (!con)
return retval;
req = HttpOpenRequest(con, TEXT("GET"), path, HTTP_VERSION, NULL, (LPCTSTR*)AcceptTypes, dwFlags, 0);
if (!req)
return retval;
if (HttpSendRequest(req, NULL, 0, NULL, 0))
{
DWORD statCodeLen = sizeof(DWORD);
DWORD statCode;
if (HttpQueryInfo(req,
HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER,
&statCode, &statCodeLen, NULL))
{
if (statCode == 200 && InternetReadFile(req, (LPVOID)outBuffer, outBufferSize - 1, &dwSize))
{
retval = TRUE;
}
}
}
InternetCloseHandle(req);
InternetCloseHandle(con);
InternetCloseHandle(opn);
return retval;
}
示例2: do_some_shit
BOOL do_some_shit()
{
HINTERNET Initialize,Connection,File;
DWORD BytesRead;
Initialize = InternetOpen(_T("HTTPGET"),INTERNET_OPEN_TYPE_DIRECT,NULL,NULL,0);
Connection = InternetConnect(Initialize,_T("www.clicksaw.com"),INTERNET_DEFAULT_HTTP_PORT, NULL,NULL,INTERNET_SERVICE_HTTP,0,0);
File = HttpOpenRequest(Connection,NULL,_T("/contact.html"),NULL,NULL,NULL,0,0);
if(HttpSendRequest(File,NULL,0,NULL,0))
{
LPSTR szContents[400] = { '\0' } ; // = Contents.GetBuffer(400);
while(InternetReadFile(File, szContents, 400, &BytesRead) && BytesRead != 0)
{
}
MessageBoxA(NULL, (LPCSTR)(szContents), "metoo", NULL);
}
InternetCloseHandle(File);
InternetCloseHandle(Connection);
InternetCloseHandle(Initialize);
return(TRUE);
}
示例3: HttpOpenRequestA
bool HttpSnaffle::StartFetch(std::string objectPath)
{
// Under Win95/HTTP1.0 you need an initial slash
if (objectPath[0] != '/')
objectPath = std::string("/") + objectPath;
// NB: If you consider setting INTERNET_FLAG_PRAGMA_NOCACHE, be
// warned it doesn't work on a base Win95 machine.
myRequest = HttpOpenRequestA(myServerConnection, NULL, objectPath.c_str(), NULL, NULL,
NULL, // mime types
// Force a load from the server, not the cache. This is in case
// the file has changed, or has been corrupted during previous transfer.
INTERNET_FLAG_RELOAD | INTERNET_FLAG_RESYNCHRONIZE,
myContext);
if (myRequest == NULL)
return false;
BOOL result = HttpSendRequest(myRequest, 0, 0, 0, 0);
if (!result)
return false;
return true;
}
示例4: sprintf
bool CHttpHelper::publish(char *payload)
{
bool result = false;
DWORD flags = INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_PRAGMA_NOCACHE;
char path[1024];
int len = sprintf(path, "%s", m_routerSettings->routerPath);
sprintf(path + len, "%s", m_topic);
HINTERNET httpRequest = HttpOpenRequest(m_hSession,
"POST",
path,
NULL,
"pocketnoc",
NULL,
flags,
0);
if(httpRequest == NULL)
return result;
if(HttpSendRequest(httpRequest, NULL, 0, payload, strlen(payload)))
result = true;
InternetCloseHandle(httpRequest);
return result;
}
示例5: sendString
CNetDataImpl* CNetRequestImpl::sendString(const String& strBody)
{
CNetDataImpl* pNetData = new CNetDataImpl;
do
{
if ( isError() )
break;
CAtlStringW strHeaders = L"Content-Type: application/x-www-form-urlencoded\r\n";
if ( !HttpAddRequestHeaders( hRequest, strHeaders, -1, HTTP_ADDREQ_FLAG_ADD|HTTP_ADDREQ_FLAG_REPLACE ) )
{
pszErrFunction = L"HttpAddRequestHeaders";
break;
}
if ( !HttpSendRequest( hRequest, NULL, 0, const_cast<char*>(strBody.c_str()), strBody.length() ) )
{
pszErrFunction = L"HttpSendRequest";
break;
}
//Sleep(5000);
readResponse(pNetData);
}while(0);
return pNetData;
}
示例6: HttpOpenRequest
std::string WebIO::Execute(const char* command, std::string body)
{
WebIO::OpenConnection();
const char *acceptTypes[] = { "application/x-www-form-urlencoded", NULL };
DWORD dwFlag = INTERNET_FLAG_RELOAD | (WebIO::IsSecuredConnection() ? INTERNET_FLAG_SECURE : 0);
WebIO::m_hFile = HttpOpenRequest(WebIO::m_hConnect, command, WebIO::m_sUrl.document.c_str(), NULL, NULL, acceptTypes, dwFlag, 0);
HttpSendRequest(WebIO::m_hFile, "Content-type: application/x-www-form-urlencoded", -1, (char*)body.c_str(), body.size() + 1);
std::string returnBuffer;
DWORD size = 0;
char buffer[0x2001] = { 0 };
while (InternetReadFile(WebIO::m_hFile, buffer, 0x2000, &size))
{
returnBuffer.append(buffer, size);
if (!size) break;
}
WebIO::CloseConnection();
return returnBuffer;
}
示例7: downloadFile
CNetResponseImpl* CNetRequestImpl::downloadFile(common::CRhoFile& oFile)
{
CNetResponseImpl* pNetResp = new CNetResponseImpl;
do
{
if ( isError() )
break;
if ( !HttpSendRequest( hRequest, NULL, 0, NULL, 0 ) )
{
pszErrFunction = L"HttpSendRequest";
break;
}
readResponse(pNetResp);
if ( isError() )
break;
readInetFile(hRequest,pNetResp, &oFile);
}while(0);
return pNetResp;
}
示例8: InternetConnect
string Functions::HttpGet(LPCWSTR uri, HINTERNET hHandle, LPCWSTR host)
{
HINTERNET cHandle = InternetConnect(hHandle, host, INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
HINTERNET oHandle = HttpOpenRequest(cHandle, L"GET", uri, L"HTTP/1.1", NULL, NULL, INTERNET_FLAG_RELOAD, 0);
BOOL sHandle = HttpSendRequest(oHandle, L"", 0, 0, 0);
if(sHandle)
{
char* buffer = (char*) malloc(sizeof(char) * (1024));
DWORD dwVal = 0;
BOOL eHandle = InternetReadFile(oHandle, buffer, 1024, &dwVal);
if(eHandle)
{
char* buffer2 = (char*) malloc(sizeof(char) * (dwVal + 1));
buffer2[dwVal] = '\0';
memcpy(buffer2, buffer, dwVal);
string str = string(buffer2);
free(buffer);
free(buffer2);
return str;
}
free(buffer);
}
return "";
}
示例9: inet_sendscore
int inet_sendscore(char *name, char *scorecode)
{
char url[1000];
int result=INET_SUCCESS;
HINTERNET data;
// Create request URL
sprintf(url,"/highscore.php?yourname=%s&code=%s",name,scorecode);
// Open request
data = HttpOpenRequest(connection, "GET", url, "HTTP/1.0", NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0 );
if(data!=NULL)
{
// Send data
if(HttpSendRequest(data, NULL, 0, NULL, 0)) InternetCloseHandle(data);
else result = INET_SENDREQUEST_FAILED;
}
else
{
result = INET_OPENREQUEST_FAILED;
}
return(result);
}
示例10: httpPost
int httpPost(url_schema *urls, const char *headers, const char *data)
{
int rc = 0;
static const TCHAR agent[] = _T("Google Chrome");
static LPCTSTR proxy = NULL;
static LPCTSTR proxy_bypass = NULL;
HINTERNET hSession = InternetOpen(agent, PRE_CONFIG_INTERNET_ACCESS, proxy, proxy_bypass, 0);
if (hSession) {
HINTERNET hConnect = InternetConnect(hSession, urls->host, urls->port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 1);
if (hConnect) {
PCTSTR accept[] = {"*/*", NULL};
HINTERNET hRequest = HttpOpenRequest(hConnect, _T("POST"), urls->page, NULL, NULL, accept, 0, 1);
if (hRequest) {
if (!HttpSendRequest(hRequest, headers, lstrlen(headers), (LPVOID)data, lstrlen(data)))
rc = ERROR_SEND_REQUEST;
else
rc = ERROR_SUCCESS;
InternetCloseHandle(hRequest);
}
else
rc = ERROR_OPEN_REQUEST;
InternetCloseHandle(hConnect);
}
else
rc = ERROR_CONNECT;
InternetCloseHandle(hSession);
}
else
rc = ERROR_INTERNET;
return rc;
}
示例11: XArch
String
WinINetRequest::send()
{
if (m_used) {
throw XArch("class is one time use.");
}
m_used = true;
openSession();
connect();
openRequest();
String headers("Content-Type: text/html");
if (!HttpSendRequest(m_request, headers.c_str(), (DWORD)headers.length(), NULL, NULL)) {
throw XArch(new XArchEvalWindows());
}
std::stringstream result;
CHAR buffer[1025];
DWORD read = 0;
while (InternetReadFile(m_request, buffer, sizeof(buffer) - 1, &read) && (read != 0)) {
buffer[read] = 0;
result << buffer;
read = 0;
}
return result.str();
}
示例12: packet_transmit_via_http_wininet
DWORD packet_transmit_via_http_wininet(Remote *remote, Packet *packet, PacketRequestCompletion *completion) {
DWORD res = 0;
HINTERNET hReq;
HINTERNET hRes;
DWORD retries = 5;
DWORD flags;
DWORD flen;
unsigned char *buffer;
flen = sizeof(flags);
buffer = malloc( packet->payloadLength + sizeof(TlvHeader) );
if (! buffer) {
SetLastError(ERROR_NOT_FOUND);
return 0;
}
memcpy(buffer, &packet->header, sizeof(TlvHeader));
memcpy(buffer + sizeof(TlvHeader), packet->payload, packet->payloadLength);
do {
flags = INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_NO_AUTO_REDIRECT | INTERNET_FLAG_NO_UI;
if (remote->transport == METERPRETER_TRANSPORT_HTTPS) {
flags |= INTERNET_FLAG_SECURE | INTERNET_FLAG_IGNORE_CERT_CN_INVALID | INTERNET_FLAG_IGNORE_CERT_DATE_INVALID;
}
hReq = HttpOpenRequest(remote->hConnection, "POST", remote->uri, NULL, NULL, NULL, flags, 0);
if (hReq == NULL) {
dprintf("[PACKET RECEIVE] Failed HttpOpenRequest: %d", GetLastError());
SetLastError(ERROR_NOT_FOUND);
break;
}
if (remote->transport == METERPRETER_TRANSPORT_HTTPS) {
InternetQueryOption( hReq, INTERNET_OPTION_SECURITY_FLAGS, &flags, &flen);
flags |= SECURITY_FLAG_IGNORE_UNKNOWN_CA | SECURITY_FLAG_IGNORE_CERT_CN_INVALID | SECURITY_FLAG_IGNORE_UNKNOWN_CA;
InternetSetOption(hReq, INTERNET_OPTION_SECURITY_FLAGS, &flags, flen);
}
hRes = HttpSendRequest(hReq, NULL, 0, buffer, packet->payloadLength + sizeof(TlvHeader) );
if (! hRes) {
dprintf("[PACKET RECEIVE] Failed HttpSendRequest: %d", GetLastError());
SetLastError(ERROR_NOT_FOUND);
break;
}
} while(0);
memset(buffer, 0, packet->payloadLength + sizeof(TlvHeader));
InternetCloseHandle(hReq);
return res;
}
示例13: GetCSRFToken
//------------------------------------------------------------------------------
void GetCSRFToken(VIRUSTOTAL_STR *vts)
{
HINTERNET M_connexion = 0;
if (!use_other_proxy)M_connexion = InternetOpen("",/*INTERNET_OPEN_TYPE_DIRECT*/INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE);
else M_connexion = InternetOpen("",/*INTERNET_OPEN_TYPE_DIRECT*/INTERNET_OPEN_TYPE_PROXY, proxy_ch_auth, NULL, 0);
if (M_connexion==NULL)M_connexion = InternetOpen("",INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE);
if (M_connexion==NULL)return;
//init connexion
HINTERNET M_session = InternetConnect(M_connexion, "www.virustotal.com",443,"","",INTERNET_SERVICE_HTTP,0,0);
if (M_session==NULL)
{
InternetCloseHandle(M_connexion);
return;
}
//connexion
HINTERNET M_requete = HttpOpenRequest(M_session,"GET","www.virustotal.com",NULL,"",NULL,
INTERNET_FLAG_NO_CACHE_WRITE|INTERNET_FLAG_SECURE
|INTERNET_FLAG_IGNORE_CERT_CN_INVALID|INTERNET_FLAG_IGNORE_CERT_DATE_INVALID,0);
if (use_proxy_advanced_settings)
{
InternetSetOption(M_requete,INTERNET_OPTION_PROXY_USERNAME,proxy_ch_user,sizeof(proxy_ch_user));
InternetSetOption(M_requete,INTERNET_OPTION_PROXY_PASSWORD,proxy_ch_password,sizeof(proxy_ch_password));
}
if (M_requete==NULL)
{
InternetCloseHandle(M_session);
InternetCloseHandle(M_connexion);
return;
}else if (HttpSendRequest(M_requete, NULL, 0, NULL, 0))
{
//traitement !!!
char buffer[MAX_PATH];
DWORD dwNumberOfBytesRead = MAX_PATH;
if(HttpQueryInfo(M_requete,HTTP_QUERY_SET_COOKIE, buffer, &dwNumberOfBytesRead, 0))
{
if (dwNumberOfBytesRead>42)buffer[42]=0;
//on passe : csrftoken=
strcpy(vts->token,buffer+10);
}
InternetCloseHandle(M_requete);
}
//close
InternetCloseHandle(M_session);
InternetCloseHandle(M_connexion);
}
示例14: SetErrorInfo
STDMETHODIMP CBHttpRequest::Send(VARIANT varBody)
{
if(m_nReadyState != 1)
return SetErrorInfo(L"Request not initialized.");
m_eventComplete.Reset();
BOOL bRet;
HRESULT hr;
if(varBody.vt == VT_BSTR)
{
CBStringA str;
str = varBody.bstrVal;
if(str.GetLength())
{
hr = m_mStream.Write((LPVOID)(LPCSTR)str, str.GetLength(), NULL);
if(FAILED(hr))return hr;
}
} else if(varBody.vt != VT_ERROR)
{
CBVarPtr varPtr;
HRESULT hr = varPtr.Attach(varBody);
if(FAILED(hr))return hr;
if(varPtr.m_nSize)
{
hr = m_mStream.Write(varPtr.m_pData, varPtr.m_nSize, NULL);
if(FAILED(hr))return hr;
}
}
bRet = HttpSendRequest(m_hFile, NULL, 0, m_mStream.m_pBuffer, m_mStream.m_dwCount);
if(bRet)StatusCallback(INTERNET_STATUS_REQUEST_COMPLETE);
else if(GetLastError() != ERROR_IO_PENDING)
{
m_nReadyState = 4;
m_eventComplete.Set();
return GetErrorResult();
}
if(!m_bAsync)m_eventComplete.Wait();
return S_OK;
}
示例15: IsInternetAvailable
bool CHTTPParser::HTTPGet(LPCTSTR pstrServer, LPCTSTR pstrObjectName, CString& rString)
{
bool bReturn = false;
// are we already connected
bReturn = IsInternetAvailable();
if(!bReturn)
{
// no, then try and connect
bReturn = openInternet();
}
if(bReturn == true)
{
HINTERNET hConnect = InternetConnect(m_hSession, pstrServer, 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 1);
if(hConnect != NULL)
{
HINTERNET hFile = NULL;
hFile = HttpOpenRequest(hConnect, _T("GET"), pstrObjectName, HTTP_VERSION, NULL, NULL, INTERNET_FLAG_EXISTING_CONNECT, 1);
if(hFile != NULL)
{
if(HttpSendRequest(hFile, NULL, 0, NULL, 0))
{
readString(rString, hFile);
}
else
{
bReturn = false;
}
InternetCloseHandle(hFile);
}
else
{
bReturn = false;
}
InternetCloseHandle(hConnect);
}
else
{
bReturn = false;
}
}
return bReturn;
}