Walter,
I don't know anything about the proxy server except I had to request special
userid/password to use to get outside of it. Corporate security requirement.
The VB6/ITC code was snatched from MS site example years ago. Even you guys
used some ugly logic for proxy - complete with built in retries. This is the
part you want. Once this piece works, then the file get just sucks data into
it:
lOptionBufferLen = 0
sProgress = "HttpOpenRequest"
glHttpOpenRequestHndl = HttpOpenRequest(glInternetConnectHndl, "GET",
gsWebSite, "HTTP/1.0", vbNullString, 0, _
INTERNET_FLAG_RELOAD Or INTERNET_FLAG_KEEP_CONNECTION Or
SecFlag, 0)
If CBool(glHttpOpenRequestHndl) Then
sProgress = "HttpAddRequestHeaders1"
sHeader = "Accept-Language: en" & vbCrLf
iRetVal = HttpAddRequestHeaders(glHttpOpenRequestHndl, sHeader,
Len(sHeader), HTTP_ADDREQ_FLAG_REPLACE Or HTTP_ADDREQ_FLAG_ADD)
sProgress = "HttpAddRequestHeaders2"
sHeader = "Connection: Keep-Alive" & vbCrLf
iRetVal = HttpAddRequestHeaders(glHttpOpenRequestHndl, sHeader,
Len(sHeader), HTTP_ADDREQ_FLAG_REPLACE Or HTTP_ADDREQ_FLAG_ADD)
sProgress = "InternetSetOption1"
dwTimeOut = 420000 ' time out is set to 7 minutes
iRetVal = InternetSetOption(glHttpOpenRequestHndl,
INTERNET_OPTION_CONNECT_TIMEOUT, dwTimeOut, 4)
If iRetVal = 0 Then
Call C090_Logit(mcMODNAME, "M030_Prepare_For_Proxy_Connection",
sProgress & " iRetVal=" & iRetVal & " Err.LastDllError=" & Err.LastDllError &
" " & "INTERNET_OPTION_CONNECT_TIMEOUT", mCommon.gcAPPWARNING)
End If
sProgress = "InternetSetOption2"
iRetVal = InternetSetOption(glHttpOpenRequestHndl,
INTERNET_OPTION_RECEIVE_TIMEOUT, dwTimeOut, 4)
If iRetVal = 0 Then
Call C090_Logit(mcMODNAME, "M030_Prepare_For_Proxy_Connection",
sProgress & " iRetVal=" & iRetVal & " Err.LastDllError=" & Err.LastDllError &
" " & "INTERNET_OPTION_RECEIVE_TIMEOUT", mCommon.gcAPPWARNING)
End If
sProgress = "InternetSetOption3"
iRetVal = InternetSetOption(glHttpOpenRequestHndl,
INTERNET_OPTION_SEND_TIMEOUT, dwTimeOut, 4)
If iRetVal = 0 Then
Call C090_Logit(mcMODNAME, "M030_Prepare_For_Proxy_Connection",
sProgress & " iRetVal=" & iRetVal & " Err.LastDllError=" & Err.LastDllError &
" " & "INTERNET_OPTION_SEND_TIMEOUT", mCommon.gcAPPWARNING)
End If
Resend:
intCtr = intCtr + 1
sProgress = "HttpSendRequest"
If intCtr > 1 Then
Call C090_Logit(mcMODNAME, "M030_Prepare_For_Proxy_Connection",
"Invoking Resend for the " & intCtr & " time", mCommon.gcAPPINFO)
If intCtr >= giProxyRetries Then
' Abend
Call C090_Logit(mcMODNAME,
"M030_Prepare_For_Proxy_Connection", "ProxyRetries (" & giProxyRetries & ")
exceeded. Check for possible ProxyUID or ProxyPWD being wrong.",
mCommon.gcAPPERROR)
gbErrorEncountered = True
Exit Function
End If
End If
iRetVal = HttpSendRequest(glHttpOpenRequestHndl, vbNullString, 0,
sOptionBuffer, lOptionBufferLen)
If (iRetVal <> 1) And (Err.LastDllError = 12045) Then
'Certificate Authority is invalid.
Call C090_Logit(mcMODNAME, "M030_Prepare_For_Proxy_Connection",
"Invalid Cert Auth, resending", mCommon.gcAPPWARNING)
dwSecFlag = SECURITY_FLAG_IGNORE_UNKNOWN_CA
iRetVal = InternetSetOption(glHttpOpenRequestHndl,
INTERNET_OPTION_SECURITY_FLAGS, dwSecFlag, 4)
If CBool(iRetVal) Then
Call C090_Logit(mcMODNAME,
"M030_Prepare_For_Proxy_Connection", sProgress & " iRetVal=" & iRetVal & "
Err.LastDllError=" & Err.LastDllError & " " &
"INTERNET_OPTION_SECURITY_FLAGS", mCommon.gcAPPWARNING)
End If
GoTo Resend
ElseIf (iRetVal <> 1) And (Err.LastDllError = 12007) Then
'Could not resolve server name.
Call Sleep(60000)
lRC = DoEvents()
Call C090_Logit(mcMODNAME, "M030_Prepare_For_Proxy_Connection",
"Name could not be resolved, resending", mCommon.gcAPPWARNING)
GoTo Resend
End If
If CBool(iRetVal) Then
Dim dwStatus As Long, dwStatusSize As Long
dwStatusSize = Len(dwStatus)
sProgress = "HttpQueryInfo"
HttpQueryInfo glHttpOpenRequestHndl, HTTP_QUERY_FLAG_NUMBER Or
HTTP_QUERY_STATUS_CODE, dwStatus, dwStatusSize, 0
If bSkipServiceId Then
Call C090_Logit(mcMODNAME,
"M030_Prepare_For_Proxy_Connection", "ServiceId is set to NONE, bypass
setting userid/password", mCommon.gcAPPWARNING)
Else
Select Case dwStatus
Case HTTP_STATUS_PROXY_AUTH_REQ
iRetVal = InternetSetOptionStr(glHttpOpenRequestHndl,
INTERNET_OPTION_PROXY_USERNAME, _
strProxyUID, Len(strProxyUID) + 1)
iRetVal = InternetSetOptionStr(glHttpOpenRequestHndl,
INTERNET_OPTION_PROXY_PASSWORD, _
strProxyPWD, Len(strProxyPWD) + 1)
GoTo Resend
Case HTTP_STATUS_DENIED
iRetVal = InternetSetOptionStr(glHttpOpenRequestHndl,
INTERNET_OPTION_USERNAME, _
strProxyUID, Len(strProxyUID) + 1)
iRetVal = InternetSetOptionStr(glHttpOpenRequestHndl,
INTERNET_OPTION_PASSWORD, _
strProxyPWD, Len(strProxyPWD) + 1)
GoTo Resend
End Select
End If
' Good - Past Proxy
blnRC = True
Else
' HttpSendRequest failed
Call C090_Logit(mcMODNAME, "M030_Prepare_For_Proxy_Connection",
"HttpSendRequest call failed; " & sProgress & " - iRetVal=" & iRetVal & "
Err.LastDllError=" & Err.LastDllError & ".", mCommon.gcAPPERROR)
End If
Else
' HttpOpenRequest failed
Call C090_Logit(mcMODNAME, "M030_Prepare_For_Proxy_Connection",
"HttpOpenRequest call failed; " & sProgress & " - Error code: " &
Err.LastDllError & ".", mCommon.gcAPPERROR)
End If
[quoted text, click to view] "Walter Wang [MSFT]" wrote:
> Hi,
>
> Thanks for the code.
>
> You once mentioned that accessing the root url succeeds, only the .csv file
> failed to download, is that still the case?
>
> It now seems related to the proxy server setting. The web site
> "http://www.ffiec.gov" can be accessed from my side, therefore I don't
> think you will need specify myWebClient.Credentials; instead, I think all
> you needed is to setup the Proxy correctly.
>
> Could you please tell me more about the proxy you're using? For example,