![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | HttpWebRequest won't work in PowerShell without a Proxy I am trying to get a web page using System.Net.HttpWebRequest. When there is no web proxy in use, it won't work. However, when there is a proxy, it works without problem. I can reproduce the problem from the command line as follows: PS C:\> $httpRequest = [System.Net.WebRequest]::Create("http://www.microsoft.com") PS C:\> $x=$httpRequest.GetResponse() Exception calling "GetResponse" with "0" argument(s): "The underlying connection was closed: An unexpected error occurr ed on a receive." At line:1 char:28 + $x=$httpRequest.GetResponse( <<<< ) PS C:\> $x=$httpRequest.GetResponse() But, PS C:\> remove-variable httprequest PS C:\> $httpRequest = [System.Net.WebRequest]::Create("http://www.microsoft.com") PS C:\> $httpRequest.Proxy = new-object -typename System.Net.WebProxy -argumentlist "http://proxy.xxx.com:8080" #actual proxy name removed for security reasons PS C:\> $x=$httpRequest.GetResponse() PS C:\> I am not sure whether this is a .NET Framework problem or a PowerShell problem. But I use the same code in a Console program compiled in Visual Studio and it runs fine. I am using .NET Framework 2.0 for the PowerShell script and 1.1 for Visual Studio 2003. Thanks for any leads. -kk |
My System Specs![]() |
| | #2 (permalink) |
| Guest | Re: HttpWebRequest won't work in PowerShell without a Proxy I've had no issues using WebRequest.Create to create an Http request without using a proxy. So it works at least sometimes. -- Don Jones Windows PowerShell MVP Founder: www.ScriptingAnswers.com Co-Author: "Windows PowerShell: TFM" "K Kong" <KKong@discussions.microsoft.com> wrote in message news:038B0946-4224-4394-8B20-00DD5546AEC7@microsoft.com... >I am trying to get a web page using System.Net.HttpWebRequest. When there >is > no web proxy in use, it won't work. However, when there is a proxy, it > works > without problem. I can reproduce the problem from the command line as > follows: > > PS C:\> $httpRequest = > [System.Net.WebRequest]::Create("http://www.microsoft.com") > PS C:\> $x=$httpRequest.GetResponse() > Exception calling "GetResponse" with "0" argument(s): "The underlying > connection was closed: An unexpected error occurr > ed on a receive." > At line:1 char:28 > + $x=$httpRequest.GetResponse( <<<< ) > PS C:\> $x=$httpRequest.GetResponse() > > But, > > PS C:\> remove-variable httprequest > PS C:\> $httpRequest = > [System.Net.WebRequest]::Create("http://www.microsoft.com") > PS C:\> $httpRequest.Proxy = new-object -typename System.Net.WebProxy > -argumentlist "http://proxy.xxx.com:8080" #actual proxy name removed for > security reasons > PS C:\> $x=$httpRequest.GetResponse() > PS C:\> > > I am not sure whether this is a .NET Framework problem or a PowerShell > problem. But I use the same code in a Console program compiled in Visual > Studio and it runs fine. I am using .NET Framework 2.0 for the PowerShell > script and 1.1 for Visual Studio 2003. > > Thanks for any leads. > > -kk |
My System Specs![]() |
| | #3 (permalink) |
| Guest | Re: HttpWebRequest won't work in PowerShell without a Proxy K Kong wrote: > I am trying to get a web page using System.Net.HttpWebRequest. When there is > no web proxy in use, it won't work. However, when there is a proxy, it works > without problem. I can reproduce the problem from the command line as > follows: > > PS C:\> $httpRequest = > [System.Net.WebRequest]::Create("http://www.microsoft.com") > PS C:\> $x=$httpRequest.GetResponse() > Exception calling "GetResponse" with "0" argument(s): "The underlying > connection was closed: An unexpected error occurr > ed on a receive." > At line:1 char:28 > + $x=$httpRequest.GetResponse( <<<< ) > PS C:\> $x=$httpRequest.GetResponse() > > But, > > PS C:\> remove-variable httprequest > PS C:\> $httpRequest = > [System.Net.WebRequest]::Create("http://www.microsoft.com") > PS C:\> $httpRequest.Proxy = new-object -typename System.Net.WebProxy > -argumentlist "http://proxy.xxx.com:8080" #actual proxy name removed for > security reasons > PS C:\> $x=$httpRequest.GetResponse() > PS C:\> > > I am not sure whether this is a .NET Framework problem or a PowerShell > problem. But I use the same code in a Console program compiled in Visual > Studio and it runs fine. I am using .NET Framework 2.0 for the PowerShell > script and 1.1 for Visual Studio 2003. > > Thanks for any leads. > > -kk Do you normally go through this proxy for web browsing? Rob Kenny |
My System Specs![]() |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| .Net 2.0 issue with HttpWebRequest/Proxy breaking WebService | LarryKuperman | .NET General | 0 | 05-12-2008 02:02 PM |
| Does Windows mail work through proxy? | Al | Vista mail | 4 | 04-22-2008 04:16 PM |
| Ok... Can someone tell me why I cant get delprof.exe to work with powershell? | Brandon Shell | PowerShell | 14 | 01-10-2007 11:07 AM |
| Don`t work behind ms proxy 2.0 | =?Utf-8?B?Q2FybG9zIEVzcXVlcnJl?= | Vista mail | 6 | 09-07-2006 04:35 PM |