forked from aciertoweb/Powershell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
http-headers.ps1
30 lines (26 loc) · 911 Bytes
/
http-headers.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
## zie: http://scriptolog.blogspot.nl/2007/08/query-http-status-codes-and-headers.html
clear
write-host "Method 1: Xml Http (com object)"
$url = "http://www.nu.nl"
$xHTTP = new-object -com msxml2.xmlhttp;
$xHTTP.open("HEAD",$url,$false);
$xHTTP.send();
$xHTTP.status # returns the status code
$xHTTP.statusText
# $xHTTP.getAllResponseHeaders()
$xHTTP.getResponseHeader("Content-Length")
# $xHTTP.ResponseText; # returns the html doc like downloadstring
Write-Host "Method 2: System.Net.HttpWebRequest"
$url = "http://www.nu.nl"
$req=[system.Net.HttpWebRequest]::Create($url);
$res = $req.getresponse();
$stat = $res.statuscode;
$res.Close();
$res.GetResponseHeader("Content-Length")
$res.StatusCode
$res.CharacterSet
Write-Host "Method 3: System.Net.WebClient"
$url="http://www.nu.nl"
$wc = new-object net.webclient
$html = $wc.DownloadString($url)
$wc.Encoding.BodyName