Invoke-RestMethod is not working
With the CURL.exe I am able o download,put and delete a file.
--For downloading the file.--
curl -o Desktop/uday.xml -u admin:Notallowed1! -X GET http://192.168.1.10:8081/artifactory/example-repo-local/idman627build5.xml
or
curl -O -u admin:Notallowed1! -X GET http://192.168.1.10:8081/artifactory/example-repo-local/idman627build5.xml
I can use without credential also as the readonly access is given to everyone.
curl -o Desktop/uday.xml -X GET http://192.168.1.10:8081/artifactory/example-repo-local/idman627build5.xml
So the Invoke-RestMethod is working.
Invoke-RestMethod -Method GET -Uri "http://192.168.1.10:8081/artifactory/example-repo-local/idmn627build5.exe" -OutFile "c:\users\ukreddy\Desktop\d.exe"
But for deleting or put/upload we require credentials.
Upload:
curl -u admin:Notallowed1! -X PUT http://192.168.1.10:8081/artifactory/example-repo-local/idman627build5.xml -T Desktop/ff.xml
Delete:
curl -u admin:Notallowed1! -X DELETE http://192.168.1.10:8081/artifactory/example-repo-local/idman627build5.xml
So, when I try to pass credential object, the powershell commandlet is not working..
$r = get-credential
In the I am passing the crendentials to $r variable when the credentials prompt appeared..
Invoke-RestMethod -Method DELETE -Uri "http://192.168.1.10:8081/artifactory/example-repo-local/idman627build5.exe" -credential $r
But I am getting below error.
------------------------------------------------
Invoke-RestMethod : The remote server returned an error: (403) Forbidden.
At line:1 char:1
+ Invoke-RestMethod -Method DELETE -Uri "http://192.168.1.10:8081/artif ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExc
eption
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
-----------------------------------------------
Can anyone suggest how to do this...
1 Comment
[ + ] Show comment
Answers (0)
Please log in to answer
Be the first to answer this question
(Invoke-RestMethod -Method GET -Uri "http://192.168.1.10:8081/artifactory/api/system/version").version - ur00361883 7 years ago