Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

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.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

HttpWebRequest won't work in PowerShell without a Proxy

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 05-11-2007   #1 (permalink)
K Kong
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 SpecsSystem Spec
Old 05-11-2007   #2 (permalink)
Don Jones [MVP]
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 SpecsSystem Spec
Old 05-12-2007   #3 (permalink)
Rob Kenny
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 SpecsSystem Spec
Closed Thread

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


Update your Vista Drivers Update Your Drivers Now!!

Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008