在我的代码中,有以下几行
Dim Http2 As New WinHttpRequest
Http2.Open "GET", URL2, False
Http2.Send当执行第三行时,excel变黑,似乎没有响应。有没有办法获得操作的状态?我可以做一个进度条吗?
发布于 2020-05-12 00:36:02
如果将http2变量声明为WithEvents,则可以执行以下操作:
Option Explicit
Private WithEvents Http2 As WinHttpRequest
Private URL2 As String
Private Sub CommandButton1_Click()
Set Http2 = New WinHttpRequest
Http2.Open "GET", URL2, False
Http2.Send
End Sub
Private Sub Http2_OnResponseStart(ByVal Status As Long, ByVal ContentType As String)
ProgressBar1.Value = 0
ProgressBar1.Max = CSng(Http2.GetResponseHeader("Content-Length"))
End Sub
Private Sub Http2_OnResponseDataAvailable(Data() As Byte)
ProgressBar1.Value = ProgressBar1.Value + UBound(Data)
End Sub如果"Content-Length“头不可用,一种选择是播放某种动画:
Private Sub Http2_OnResponseStart(ByVal Status As Long, ByVal ContentType As String)
Animation1.Visible = True
Animation1.Open "filecopy.avi"
Animation1.Play
End Sub
Private Sub Http2_OnResponseFinished()
Animation1.Stop
Animation1.Close
Animation1.Visible = False
End Sub发布于 2020-05-13 00:35:32
谢谢你的回答,但它不起作用。没有Content-Lenght标头。下面是GetAllResponseHeaders的结果
Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
Connection: Keep-Alive
Date: Tue, 12 May 2020 16:30:23 GMT
Keep-Alive: timeout=5, max=100
Pragma: no-cache
Transfer-Encoding: chunked
Content-Type: text/html;charset=utf-8
Expires: Tue, 12 May 2020 16:30:23 GMT
Server: Apache
Set-Cookie: JSESSIONID=Sa-cFWD2CHr2DjK0+KE6GH4r; Path=/pvp; Secure;HttpOnly;Secure
Set-Cookie: ROUTEIDPVP=.14; path=/pvp; HTTPOnly; Secure
Vary: Accept-Encoding
Strict-Transport-Security: max-age=63072000; includeSubdomains;
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
X-Frame-Options: DENY此外,我还必须将代码编写为Class Module
https://stackoverflow.com/questions/61732363
复制相似问题