Results 1 to 8 of 8

Thread: [RESOLVED] httpwebrequest

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    382

    Resolved [RESOLVED] httpwebrequest

    when HttpWebRequest object talk to HTTP Servers. project is hang for 4-5 second until server give response how to came out from this problem

    VBcode Code:
    1. Try
    2.             Dim URL As String = "http://www.vbforums.com/"
    3.             Dim request As HttpWebRequest = WebRequest.Create(URL)
    4.             Dim response As HttpWebResponse = request.GetResponse()
    5.             Dim reader As StreamReader = New StreamReader(response.GetResponseStream())
    6.         Catch e1 As Exception
    7.             responseData = "An error occurred: " & e1.Message
    8.         End Try

  2. #2
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: httpwebrequest

    when you ask your browser to initiate a web-request some time passes too.
    It may be caused by a firewall or a slow connection. Your code is correct and nothing can be improved.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    382

    Re: httpwebrequest

    I want that vb.net project/form will not hang or freeze when it is in progree it just remain normal

    Any property or method i miss ?
    Last edited by CatchItBaby; Aug 2nd, 2010 at 07:04 AM.

  4. #4
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: httpwebrequest

    You can initiate your web request asynchronously (in another thread) so that your UI won't be blocked.
    Use BeginGetResponse instead of GetResponse.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    382

    Re: httpwebrequest

    so i need to understand multithreading (My Level = NULL) concept first ?

  6. #6
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: httpwebrequest

    Look into using a backgroundworker to do the work and tell you when its finished so your main app can carry on working. There are loads of examples in the forums.

    Edit: Actually cicatrix's suggestion may be better!

  7. #7
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: httpwebrequest

    Try searching through this forum for BeginGetRequest or simply multithreading to grasp some concepts because this topic is too big to re-type it in this thread. This and the general problems that rise with multithreading.

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    382

    Re: httpwebrequest

    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width