I am trying to authenticate to JFROG from powershell i tried it with my token and its giving 403 forbidden
PS C:\Myproject> $myHeaders = #{'X-JFrog-Art-Api' = 'AKCp8sdFTEKF1Y5MDgM3M8RK6bRkKWoX43jWranZvS2U2DE82KFE7243F'}
PS C:\Myproject> Invoke-WebRequest -Uri "https://org.jfrog.io/" -Method Get -Headers $myHeaders
Invoke-WebRequest : 403 Forbidden
nginx
At line:1 char:1
+ Invoke-WebRequest -Uri "https://fiprod.jfrog.io/" -Method Get -Header ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
Any idea on how to authenticate to Artifactory via a token using PowerShell ?
So, here is the link to Jobs API call in Databricks here
Everything works in Python using requests. E.g both the job creation and job listing works
import requests
proxy= "http://127.0.0.1:8888"
access_token="tokenabc"
proxies = {
"https": proxy,
}
header_read = {
'Authorization': "Bearer " + access_token,
'Accept': "application/scim+json"
}
#list jobs
init_get=requests.get('https://databricksworkspaceid.azuredatabricks.net/api/2.0/jobs/list', headers=header_read, proxies=proxies)
#create job
init_post=requests.post('https://databricksworkspaceid.azuredatabricks.net/api/2.0/jobs/create', headers=header_read, proxies=proxies,verify=False,json=job_payload)
However, strangely in Powershell, only the job creation works and Job listing fails.
#this works
Invoke-RestMethod -Uri 'https://databricksworkspaceid.azuredatabricks.net/api/2.0/jobs/create' -Headers #{ 'Authorization' = "Bearer $bearertoken" } -Method Post -Body $content -ContentType 'application/json'
#this does not work
Invoke-WebRequest -Uri 'https://databricksworkspaceid.azuredatabricks.net/api/2.0/jobs/list' -Headers #{ 'Authorization' = "Bearer $bearertoken" } -Method Get
#RestMethod also does not work
Invoke-RestMethod -Uri 'https://databricksworkspaceid.azuredatabricks.net/api/2.0/jobs/list' -Headers #{ 'Authorization' = "Bearer $bearertoken" } -Method Get
I have also tried setting the Content type on these but nothing helps.
Also, explicitly setting the proxy (fiddler) does not help.
-proxy "http://127.0.0.1:8888"
But should not be the proxy also , as the post method works.
I just keep getting an error like
Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a send.
At line:22 char:5
+ Invoke-WebRequest -Uri 'https://databricksworkspaceid.azuredatabricks.net/ap ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
or in case of RestMethod
Invoke-RestMethod : The underlying connection was closed: An unexpected error occurred on a send.
At line:22 char:5
+ Invoke-RestMethod -Uri 'https://databricksworkspaceid.azuredatabricks.net/ap ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
I could have understood if everything failed in Powershell, but the post method (job creation) works, so not sure, why the connection would be terminated in case of a Get request but not a post.
Going by some forum posts, I have also tried the following but to no avail-
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Does anyone know what am I doing wrong/missing? Baffling to see working in python but only a part in Powershell.
So, I finally found the answer. Basically 2 things:
Had to do this before hitting the list endpoint (strangely as I said- the create endpoint) worked
Basically allowing TLS, TLS1.1 and TLS1.2
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls -bor [Net.SecurityProtocolType]::Tls11 -bor [Net.SecurityProtocolType]::Tls12
Doing only point 1 didn't work. I HAD to also use an "elevated" powershell session. Basically running the script with step 1 included, using a "Run as Administrator".
I am trying the following command
Invoke-RestMethod -Uri 'http://serverIP/my/application/URL' -Method 'GET' -WebSession $CurrentSession
I tried it with Invoke-WebRequest as well But I am getting this error for both of them
Invoke-WebRequest : An unexpected error has occurred while attempting to serialize a Date datatype.
At line:1 char:1
+ Invoke-WebRequest -Uri 'http://serverIP/my/application/UR ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
I am quite new at using the Invoke-RestMethod
Can someone please help me with this error?
Invoke-RestMethod : The underlying connection was closed: An unexpected error
occurred on a send.## Heading ##
At \Desktop\T.ps1:27 char:7
+ $CS = Invoke-RestMethod -Method PUT -Uri https://XXXX ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:Htt
pWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShe
ll.Commands.InvokeRestMethodCommand
Your error is in the script T.ps1 line: 27 char: 7, and it is related to the Invoke-ResMethod cmdlet. I'll give you an example on how to use Invoke-RestMethod.
Invoke-RestMethod -Uri "place the dns or ip you want to request" -Method (POST or Get)
Working example to request google:
Invoke-RestMethod -Uri "https://www.google.com" -Method GET
This must return the html code of google's web page
Error:
Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a send
via : proxy
powershell version 4.0, the same request works with later version of powershell
Tried to invoke web request
$headers = #{ "Authorization" = "Bearer 7jNQ0nL"}
Invoke-WebRequest -Uri https://api.line.me/v2/bot/user/all/richmenu -Method Get -Proxy proxy.xx.xxxnet.com:8080 -ProxyUseDefaultCredentials -Headers $headers
but this is what happens:
Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a send.
At line:1 char:1
+ Invoke-WebRequest -Uri https://api.line.me/v2/bot/user/all/richmenu -Method Ge ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand