开发者

Why is my VB.Net WebClient.DownloadString request taking so long?

开发者 https://www.devze.com 2023-01-11 09:22 出处:网络
I am making a request from a web server for some text and displaying it in a textbox using the following code:

I am making a request from a web server for some text and displaying it in a textbox using the following code:

    Dim client As WebClient = New WebClient()
    Dim theText As String = client.DownloadString("http://192.168.1.110/text.html")
    Me.TextBox1.Text = theText

When I run it the "client.DownloadString" command takes 6 or 7 seconds to complete (gets about 20 bytes of text). If I make this开发者_如何学运维 same request in a web browser it is basically immediate. I read a few related postings on other sites bout the proxy member (client.Proxy) needing to be null. Given VB.Net doesn't support null I set it to "Nothing" but there was no change in performance. Any ideas on why this is slow?

Update...yes, the request does succeed. It just takes 6 or 7 seconds. It is only slow the first time the call is made. If I delete the contents of the textbox and run it again, it is immediate. I have done some research on this and found that it has to do with setting the default proxy (client.Proxy) that it reads from the IE browser settings. Again, I've seen this problem addressed in other postings but never in VB.Net and the solution is always to set client.Proxy = Null. However, VB.Net doesn't support NULLs. I tried setting it to "Nothing" but it didn't seem to help.


I had the same issue with long delays on url requests but coding as follows worked for me:

        objwebClient = New WebClient()
        objwebClient.Proxy = Nothing
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号