Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


System.Net.WebClient

 
Logged in as: Guest
arrSession:exec spGetSession 2,5,39659
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> Windows PowerShell >> System.Net.WebClient
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 System.Net.WebClient - 11/13/2006 4:47:21 AM   
  ziminski

 

Posts: 79
Score: 2
Joined: 1/8/2006
Status: offline
Does anybody know what this error is and how to get around it? 

Exception calling "DownloadString" with "1" argument(s): "The server committed a protocol violation. Section=ResponseStatusLine"
At line:1 char:57

I'm calling:

$page = (new-object System.Net.WebClient).DownloadString("http://xxx.xxx.xxx.xxx:9999")
$page

I am trying to check the responce from a time clock(s) which runs a stripped down version of linux and Apache. It uses a web interface for configuration, so I figured I can check it to see when it's on line and the service is up. (I also check it via ping and telnet service) but they could be running and the application hung.

Thanks
Rick 
 
 
Post #: 1
 
 RE: System.Net.WebClient - 11/14/2006 12:40:36 AM   
  SAPIENScripter


Posts: 276
Score: 2
Joined: 11/1/2006
From: SAPIEN Technologies
Status: offline
The command works fine if you use a host name instead of the IP address.

$page=(new-object system.net.webclient).DownloadString("http://www.jdhitsolutions.com:80")

I'm assuming the WebClient object is expecting a name and not an IP address.  

_____________________________

Jeffery Hicks
Windows PowerShell MVP
SAPIEN Technologies - Scripting, Simplified. www.SAPIEN.com

Follow Me: http://www.twitter.com/JeffHicks

(in reply to ziminski)
 
 
Post #: 2
 
 RE: System.Net.WebClient - 11/14/2006 2:54:59 AM   
  ziminski

 

Posts: 79
Score: 2
Joined: 1/8/2006
Status: offline
Unfortunately using host name produces the same error. How ever the error it's self tells me the web serviceis up. If it is not up I get an unkown host error. So a little klugee but I parse the return for the result I want like so.
$page = $web.DownloadString("http://" + $objRecordset.Fields.Item("terminalipaddress").Value + ":9999" -f $_ ) | match-string -eq "Unable to connect to the remote server"
if ($lastexitcode -eq 0){$ws.Cells.Item($r, 5) = "YES"} else { $ws.Cells.Item($r, 5) = "NO"}

It seems to work.

Rick

(in reply to SAPIENScripter)
 
 
Post #: 3
 
 RE: System.Net.WebClient - 11/14/2006 4:10:14 AM   
  SAPIENScripter


Posts: 276
Score: 2
Joined: 11/1/2006
From: SAPIEN Technologies
Status: offline
That is very odd. The only time I get your problem is if I use an IP address. Do you get the same result regardless of what hostname you use? If you used
$page=(new-object system.net.webclient).DownloadString("http://www.jdhitsolutions.com:80")
do you get the same error? I'm curious if this is a PowerShell/.NET issue or something specific to the server you are trying to connect to.

Are you running PowerShell RC2?

_____________________________

Jeffery Hicks
Windows PowerShell MVP
SAPIEN Technologies - Scripting, Simplified. www.SAPIEN.com

Follow Me: http://www.twitter.com/JeffHicks

(in reply to ziminski)
 
 
Post #: 4
 
 RE: System.Net.WebClient - 11/14/2006 7:33:43 AM   
  ziminski

 

Posts: 79
Score: 2
Joined: 1/8/2006
Status: offline
If I connect to a known windows server inside my firewall by host name  no problems.
when I connect to
PS C:\Powershell> $page=(new-object system.net.webclient).DownloadString("http://www.jdhitsolutions.com:80")
Exception calling "DownloadString" with "1" argument(s): "The underlying connection was closed: An unexpected error occurred on a receive."
At line:1 char:55
+ $page=(new-object system.net.webclient).DownloadString( <<<< "http://www.jdhitsolutions.com:80")
But this might be a firewall issue. I think the other error maybe specfic to the servers I'm trying to connect to.A stripped down version of linux and Apache
and yes PowerShell RC2

< Message edited by ziminski -- 11/14/2006 7:34:53 AM >

(in reply to SAPIENScripter)
 
 
Post #: 5
 
 RE: System.Net.WebClient - 11/14/2006 7:53:57 AM   
  SAPIENScripter


Posts: 276
Score: 2
Joined: 11/1/2006
From: SAPIEN Technologies
Status: offline
It makes sense that if you have a firewall or proxy this will cause a problem.  I don't know without some research how this class gets around or uses a proxy.

_____________________________

Jeffery Hicks
Windows PowerShell MVP
SAPIEN Technologies - Scripting, Simplified. www.SAPIEN.com

Follow Me: http://www.twitter.com/JeffHicks

(in reply to ziminski)
 
 
Post #: 6
 
 RE: System.Net.WebClient - 11/28/2006 8:13:28 AM   
  ziminski

 

Posts: 79
Score: 2
Joined: 1/8/2006
Status: offline
Found to make this work I needed to add the proxy server and UseDefaultCredentials

$webclient= new-object System.Net.WebClient
$proxy = new-object System.Net.WebProxy "proxy.server.com:8080"
$proxy.UseDefaultCredentials = $true
$webclient.proxy=$proxy
$webclient.DownloadString($url)

not sure why it would matter for an ip address inside my fire wall but it did.

hope it is usefull to someone else.
Rick

(in reply to SAPIENScripter)
 
 
Post #: 7
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> Windows PowerShell >> System.Net.WebClient Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts