Replies: 3 comments 3 replies
-
|
This automatically generated reply acts as a friendly reminder. Answers to your questions will most often come from the community, from developers like yourself. You will, from time to time, find that Axis employees answers some of the questions, but this is not a guarantee. Think of the discussion forum as a complement to other support channels, not a replacement to any of them. If your question remains unanswered for a period of time, please revisit it to see whether it can be improved by following the guidelines listed in Axis support guidelines. |
Beta Was this translation helpful? Give feedback.
-
|
@Akita54 |
Beta Was this translation helpful? Give feedback.
-
|
Hi @Akita54 ,
Powershell script (I used the ChatGPT 😉 ). Works with CMD only.# Trust all SSL certificates (PowerShell 5.1)
Add-Type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint,
X509Certificate certificate,
WebRequest request,
int certificateProblem) {
return true;
}
}
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
# Read credentials
$username = Read-Host "Username"
$password = Read-Host "Password" -AsSecureString
$plainPassword = [Runtime.InteropServices.Marshal]::PtrToStringAuto(
[Runtime.InteropServices.Marshal]::SecureStringToBSTR($password)
)
# Build Basic Auth header
$authBytes = [Text.Encoding]::ASCII.GetBytes("$($username):$($plainPassword)")
$authHeader = [Convert]::ToBase64String($authBytes)
# Invoke request
Invoke-WebRequest `
-Uri "https://10.176.12.35/config/rest/basic-device-info/v2beta" `
-Method GET `
-Headers @{
"Accept" = "application/json"
"Authorization" = "Basic $authHeader"
}
OutputE:\Vivek\Discussions\1210>powershell -ExecutionPolicy Bypass -File .\Sample1.ps1
Username: root
Password: *************
StatusCode : 200
StatusDescription : OK
Content : {
"status": "success",
"data": {
"allowAnonymous": true
}
}
RawContent : HTTP/1.1 200 OK
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Content-Security-Policy: default-src 'self'; frame-ancestors 'self'; connect-src 'self' ...
Forms : {}
Headers : {[X-Content-Type-Options, nosniff], [X-Frame-Options, SAMEORIGIN], [X-XSS-Protection, 1; mode=block], [Content-Security-Policy, default-src 'self'; frame-ancestors 'self'; connect-src 'self' https://*.google-analytics.com
https://*.analytics.google.com https://*.googletagmanager.com https://*.axis.com mediastream: blob:; script-src 'self' https://*.googletagmanager.com https://www.google-analytics.com https://ssl.google-analytics.com https://*.axis.com;
style-src 'self' 'unsafe-inline'; img-src 'self' https://*.google-analytics.com https://*.googletagmanager.com https://*.axis.com data: blob:; media-src 'self' mediastream: blob:; object-src 'none']...}
Images : {}
InputFields : {}
Links : {}
ParsedHtml : System.__ComObject
RawContentLength : 69For HTTP
Powershell script (I used the ChatGPT 😉 )$username = Read-Host "Username"
$password = Read-Host "Password" -AsSecureString
$cred = New-Object System.Net.NetworkCredential($username, $password)
$request = [System.Net.HttpWebRequest]::Create(
"http://10.176.12.35/config/rest/basic-device-info/v2beta"
)
$request.Method = "GET"
$request.Accept = "application/json"
$request.Credentials = $cred
$request.PreAuthenticate = $true
$response = $request.GetResponse()
$reader = New-Object System.IO.StreamReader($response.GetResponseStream())
$reader.ReadToEnd()
Output:PS E:\Vivek\Discussions\1210> pwsh -ExecutionPolicy Bypass -File .\Sample2.ps1
Username: root
Password: *************
{
"status": "success",
"data": {
"allowAnonymous": true
}
}
Error in PS:PS E:\Vivek\Discussions\1210> pwsh -ExecutionPolicy Bypass -File .\Sample1.ps1
Add-Type: E:\Vivek\Discussions\1210\Sample1.ps1:2:1
Line |
2 | Add-Type @"
| ~~~~~~~~~~~
| (4,36): error CS0246: The type or namespace name 'ICertificatePolicy' could not be found (are you missing a using directive or an assembly reference?) public class TrustAllCertsPolicy : ICertificatePolicy {
| ^
Add-Type: E:\Vivek\Discussions\1210\Sample1.ps1:2:1
Line |
2 | Add-Type @"
| ~~~~~~~~~~~
| Cannot add type. Compilation errors occurred.
New-Object: E:\Vivek\Discussions\1210\Sample1.ps1:17:55
Line |
17 | … vicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Cannot find type [TrustAllCertsPolicy]: verify that the assembly containing this type is loaded. |
Beta Was this translation helpful? Give feedback.





Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I’m trying to make a basic connection to my camera with the below commands. Once it gets to Invoke WebRequest, it errors. Any ideas why?
PS C: $Username = "xxxxxxxxx"
$Password = "yyyyyyyyyyy"
$AuthInfo = [Convert]::ToBase64String(
[Text.Encoding]::ASCII.GetBytes("${Username}:${Password}")
)
$Headers = @{
Authorization = "Basic $AuthInfo"
}
Invoke-WebRequest
-Uri "http://192.168.0.90/config/rest/basic-device-info/v2beta"-Method POST `
-Headers $Headers
Error
Invoke-WebRequest : Unable to connect to the remote server
At line:11 char:1
Beta Was this translation helpful? Give feedback.
All reactions