开发者

Why does this powershell script make two web requests (System.Net.HttpWebRequest)?

开发者 https://www.devze.com 2023-01-30 18:48 出处:网络
Accordin开发者_Go百科g to my server logs, the following script seems to make two web requests instead of one. Every single time the second request is exactly 2 minutes later. I only want one request.

Accordin开发者_Go百科g to my server logs, the following script seems to make two web requests instead of one. Every single time the second request is exactly 2 minutes later. I only want one request. What am I missing?

# create the web request
$request = [System.Net.HttpWebRequest]::Create($url)
# set the timeout to 1 hour
$request.Timeout = 3600000

# get the response and stream
Write-Host "GetResponse() start"
$response = $request.GetResponse()
Write-Host "GetResponse() done"

Write-Host "GetResponseStream() start"
$stream = $response.GetResponseStream()
Write-Host "GetResponseStream() end"

# read the stream
Write-Host "Read stream start"
$reader = New-Object IO.StreamReader($stream)
$html = $reader.ReadToEnd()
Write-Host "Read stream end"

# output the html response
Write-Host $html

# clean up resources
$reader.Close()
$stream.Close()
$response.Close()

Write-Host "Done"


This is not à response, but an element of help.

I copy/past your PowerShell code in PowerGuy, and just initialyse $url with "". Then I start WireShark (an open source sniffer) on my computer. You will find, here under the capture.

Why does this powershell script make two web requests (System.Net.HttpWebRequest)?

It shows only one answer/response. I suppress the other frames, but I receive "Heartbeat" from Google, nothing else and I wait for more than 2 minutes.

Once again, it's not an answer, but an element of response. You perhaps have to try to start your script from a virtual machine, in which you install WireShark.

I can make more tests, if you give me the URL of your server, the server type and technologie.

I hope it helps.

JP

0

精彩评论

暂无评论...
验证码 换一张
取 消