BOOL SetConnectionOptions()
{
INTERNET_PER_CONN_OPTION_LIST list;
BOOL bReturn;
DWORD dwBufSize = sizeof(list);
//
Fill the list structure.
list.dwSize = sizeof(list);
//
NULL == LAN, otherwise connectoid name.
list.pszConnection = NULL;
//
Set three options.
list.dwOptionCount = 3;
list.pOptions = new INTERNET_PER_CONN_OPTION[3];
//
Ensure that the memory was allocated.
if
(NULL == list.pOptions)
{
//
Return FALSE
if
the memory wasn't allocated.
return
FALSE;
}
//
Set flags.
list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
list.pOptions[0].Value.dwValue = PROXY_TYPE_DIRECT |
PROXY_TYPE_PROXY;
//
Set proxy name.
list.pOptions[1].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
list.pOptions[1].Value.pszValue =
"118.244.147.49:8080"
;
//
Set proxy override.
list.pOptions[2].dwOption = INTERNET_PER_CONN_PROXY_BYPASS;
list.pOptions[2].Value.pszValue =
"local"
;
//
Set the options on the connection.
bReturn = InternetSetOption(NULL,
INTERNET_OPTION_PER_CONNECTION_OPTION, &list, dwBufSize);
//
Free the allocated memory.
delete [] list.pOptions;
return
bReturn;
}
char* DownLoads(char* pszURL)
{
SetConnectionOptions();
HINTERNET Handle =InternetOpenA(
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0;Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; InfoPath.2; .NET CLR 2.0.50727; MS-RTC LM 8; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 1.1.4322; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)"
,1,0,0,0);
DWORD dwContext[]={0,0,0};
char* pszVerb =
"GET"
;
char* pszVersion =
"HTTP/1.1"
;
char *szBuffer= new char[4095];
DWORD dwNumberOfBytesRead;
memset(szBuffer,0,4095);
HINTERNET hURL =InternetConnectA(Handle,
"cas.sdo.com"
,0x1BB,0,0,3,0,(DWORD_PTR)dwContext);
if
(hURL == NULL)
{
MessageBoxA(0,
"InternetConnect出错"
,0,0);
return
0;
}
Handle =HttpOpenRequestA(hURL,pszVerb,pszURL,pszVersion,0,0,0x80803000,(DWORD_PTR)dwContext);
if
(HttpSendRequestW(Handle,0,0,pszVersion,0) ==NULL)
{
MessageBoxA(0,
"出现错误 HttpSendRequest"
,0,0);
return
0;
}
InternetReadFile(Handle,szBuffer,4095,&dwNumberOfBytesRead);
return
szBuffer;
}