Hi Actually this question is related to every web query giving back an html page A silly question from a dumb powersheller ;) I'm using Powershell 4.0 Here is my query:
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true} $url = "https://myprtg.domain.tld/api/duplicateobject.htm?id=61222&name=9998 FIX: Uptime&targetid=63040&username=me&password=pass"
When I do:
$result = Invoke-WebRequest $url
I have an error (since the beginning for all my functions):
Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a send. At line:1 char:11 + $result = Invoke-WebRequest $url + ~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
I used to make it like this instead:
$wc = New-Object System.Net.WebClient $url = "https://myprtg.domain.tld/api/duplicateobject.htm?id=61222&name=9998 FIX: Uptime&targetid=63040&username=me&password=pass" $result = $wc.DownloadString($url) $html = New-Object -ComObject "HTMLFile" $html.IHTMLDocument2_write($result) $html.forms | % innerhtml
This last line gives back the whole form but I can't figure out how to get the new sensor id only Do you have any suggestion? Thank you upfront
Article Comments
Hi there,
Please note that the URL might not be valid at all due to the space in between:
https://myprtg.domain.tld/api/duplicateobject.htm?id=61222&name=9998 FIX: Uptime&targetid=63040&username=me&password=pass |
Please try the following URL instead:
https://myprtg.domain.tld/api/duplicateobject.htm?id=61222&name=9998%20FIX:%20Uptime&targetid=63040&username=me&password=pass |
Does that work properly?
Best regards.
Apr, 2018 - Permalink
Actually with my method it does work as is I already have though (and tested) removing spaces with invoke-webrequest but it does not work either Actually I have something working and I keep it
Apr, 2018 - Permalink
Finally I found out a mean to make it without a com object from the result string I do:
$ResultId contains the sensor's ID
Still I am wondering why Invoke-Webrequest doesn't work
Apr, 2018 - Permalink