CURL pass, but Invoke-RestMethod fails for POST – Method not allowed Error

Welcome Forums General PowerShell Q&A CURL pass, but Invoke-RestMethod fails for POST – Method not allowed Error

Viewing 2 reply threads
  • Author
    Posts
    • #247264
      Participant
      Topics: 10
      Replies: 9
      Points: 139
      Rank: Participant

      Hi,

      I want to upload JSON file to artifactory platform. With curl from PowerShell it goes well and file is uploaded succesfully:

      curl -H ‘X-JFrog-Art-Api:AKC’ -T test1.json https://artifactory.dev/artifactory/configurations/test1.json

      But if I try to upload the same file with same key on the same path it returns error:
      Invoke-RestMethod: Response status code does not indicate success: 405 (Method Not Allowed).

      This is how I try it:
      $header = @{“X-JFrog-Art-Api” = “AKC”}
      $jsonFile=Get-Content -Raw -Path C:\Users\e5614274\Downloads\test1.json


      Invoke-RestMethod -Uri “https://artifactory.dev/artifactory/configurations/test1.json” -Headers $header -Method POST -Body $jsonFile -ContentType ‘application/json’

      But POST is certainly allowed since I succeed to upload using the CURL.
      Can someone please tell me what I am doing wrong?
      Thank you in advance for helping!!!

      • This topic was modified 1 month, 3 weeks ago by VeljkoShell.
      • This topic was modified 1 month, 3 weeks ago by VeljkoShell.
    • #248230
      Participant
      Topics: 0
      Replies: 38
      Points: 381
      Helping Hand
      Rank: Contributor

      Hello VeljkoShell,
      In curl -T/--upload-filetransfers the specified local file to the remote URL.

      For the Invoke-RestMethod try to use -InFile parameter, which gets the content of the web request from a file, as Get-Content returns a collection of objects, each of which represents a line of content.

      Hope that helps.

      • This reply was modified 1 month, 2 weeks ago by AndySvints.
    • #248440
      Participant
      Topics: 0
      Replies: 81
      Points: 362
      Helping Hand
      Rank: Contributor

      Maybe your method needs to be PUT.

Viewing 2 reply threads
  • You must be logged in to reply to this topic.