Results 1 to 7 of 7

Thread: Webproxy problem.

  1. #1

    Thread Starter
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840

    Webproxy problem.

    Hi.

    I have asked this once before, and I did get some replies, but unfortunatly none that worked.

    How to use webproxy and webrequest?
    I just get a timeout exception.
    I have also tried to set the proxy manual. Then I don't get the timeout, but "an unexpected error occured during recive".

    I found this sample on MSDN
    VB Code:
    1. Dim sURL As String
    2.         sURL = "http://www.microsoft.com"
    3.  
    4.         Dim wrGETURL As WebRequest
    5.         wrGETURL = WebRequest.Create(sURL)
    6.  
    7.         wrGETURL.Proxy = WebProxy.GetDefaultProxy()
    8.  
    9.         Dim objStream As Stream
    10.         objStream = wrGETURL.GetResponse.GetResponseStream()
    11.  
    12.         Dim objReader As New StreamReader(objStream)
    13.         Dim sLine As String = ""
    14.         Dim i As Integer = 0
    15.  
    16.         Do While Not sLine Is Nothing
    17.             i += 1
    18.             sLine = objReader.ReadLine
    19.             If Not sLine Is Nothing Then
    20.                 Console.WriteLine("{0}:{1}", i, sLine)
    21.             End If
    22.         Loop
    23.  
    24.         Console.ReadLine()

    I figured, "hey, ms made it, so it must work...". Well, it didn't. At least not for me.

    Here's some screenshots of my proxy settings in IE.



    Can anyone help me with this?
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  2. #2

    Thread Starter
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Bump
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  3. #3

    Thread Starter
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Final Bump
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  4. #4
    Fanatic Member carlblanchard's Avatar
    Join Date
    Sep 2003
    Location
    Bournemouth (UK)
    Posts
    539

    from msdn

    code is from msdn so it should work


    VB Code:
    1. ' Create a new request to the mentioned URL.                
    2. Dim myWebRequest As WebRequest = WebRequest.Create("http://www.contoso.com")
    3. Dim myProxy As New WebProxy()
    4.  
    5. ' Obtain the Proxy Prperty of the  Default browser.
    6.  myProxy = CType(myWebRequest.Proxy, WebProxy)
    7.  
    8. ' Print myProxy address to the console.
    9. Console.WriteLine(ControlChars.Cr + "The actual default Proxy settings are {0}", myProxy.Address)
    10.  
    11. Try
    12.     Console.WriteLine(ControlChars.Cr + "Please enter the new Proxy Address to be set ")
    13.     Console.WriteLine("The format of the address should be [url]http://proxyUriAddress:portaddress[/url]")
    14.     Console.WriteLine("Example:[url]http://moon.proxy.com:8080[/url]")
    15.     Dim proxyAddress As String
    16.     proxyAddress = Console.ReadLine()
    17.  
    18.     If proxyAddress.Length = 0 Then
    19.         myWebRequest.Proxy = myProxy
    20.     Else
    21.         Console.WriteLine(ControlChars.Cr + "Please enter the Credentials")
    22.         Console.WriteLine("Username:")
    23.         Dim username As String
    24.         username = Console.ReadLine()
    25.         Console.WriteLine(ControlChars.Cr + "Password:")
    26.         Dim password As String
    27.         password = Console.ReadLine()
    28.  
    29.        ' Create a new Uri object.
    30.         Dim newUri As New Uri(proxyAddress)
    31.  
    32.         ' Associate the new Uri object to the myProxy object.
    33.         myProxy.Address = newUri
    34.  
    35.         ' Create a NetworkCredential object and is assign to the Credentials property of the Proxy object.
    36.         myProxy.Credentials = New NetworkCredential(username, password)
    37.         myWebRequest.Proxy = myProxy
    38.        
    39.     End If
    40.     Console.WriteLine(ControlChars.Cr + "The Address of the  new Proxy settings are {0}", myProxy.Address)
    41.     Dim myWebResponse As WebResponse = myWebRequest.GetResponse()
    42.  
    43.     ' Print the  HTML contents of the page to the console.
    44.     Dim streamResponse As Stream = myWebResponse.GetResponseStream()
    45.  
    46.     Dim streamRead As New StreamReader(streamResponse)
    47.     Dim readBuff(256) As [Char]
    48.     Dim count As Integer = streamRead.Read(readBuff, 0, 256)
    49.     Console.WriteLine(ControlChars.Cr + "The contents of the Html pages are :")
    50.  
    51.     While count > 0
    52.         Dim outputData As New [String](readBuff, 0, count)
    53.         Console.Write(outputData)
    54.         count = streamRead.Read(readBuff, 0, 256)
    55.  
    56.     End While
    57.  
    58.            ' Close the Stream object.
    59.     streamResponse.Close()
    60.           streamRead.Close()
    61.  
    62.           ' Release the HttpWebResponse Resource.
    63. myWebResponse.Close()
    64.     Console.WriteLine(ControlChars.Cr + "Press any key to continue.........")
    65.     Console.Read()
    66. Catch e As UriFormatException
    67.     Console.WriteLine(ControlChars.Cr + "{0}", e.Message)
    68.     Console.WriteLine(ControlChars.Cr + "The format of the myProxy address you entered is invalid")
    69.  End Try
    I am curretly building a defect management system for software and web developers,
    If you wana try it out (beta test) and keep it for free just send me a message

  5. #5

    Thread Starter
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Hi.

    Thanks for the answer. Unfortunatly it didn't work.
    My conclusion is, that there must be some security thing blocking my way.

    I have tried many samples now, and none of them work, so I don't think there's anything wrong with the samples.

    It must be some firewall setting...So I guess I just have to live with it.

    But thanks for your time anyway.
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  6. #6
    Fanatic Member carlblanchard's Avatar
    Join Date
    Sep 2003
    Location
    Bournemouth (UK)
    Posts
    539
    what proxy and firewall client are you using ?

    Ive used proxy code before when using isa server and it worked fine....
    I am curretly building a defect management system for software and web developers,
    If you wana try it out (beta test) and keep it for free just send me a message

  7. #7

    Thread Starter
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Hi.

    I really don't know, actually. I'm just one of the small guys in the company, and I usually only make small test app's. Nothing that ever get's published. So unfortunatly I have no insigth or access to any of the servers. All IT is handled by our HQ, which is located in another country. And company policy is so stiff, that I have no chance in h**l to make them change anything. Not with this small app.

    This is the first time that I have tried to access the Internet from my workstation, so I thought that maybe I was doing something wrong. I have no problem using my own DSL connection at home.

    It was supposed to collect some data from various sites, but the user can just as well input the data manually.
    But I guess, they just have to miss this feature from the app.
    I don't believe it was that important. More like a "nice to have" feature. I will just have to tell them, it can't be done, with policy being as it is.


    But I still wish to thank you for your time.
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

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