Benutzer-Werkzeuge

Webseiten-Werkzeuge


windows:powershell_irm_curl_wget

curl / wget in der Powershell - Testen von ORDS Webservices in der Powershell über die Console

Unter Linux läßt sich eine Webseite mit curl oder wget sehr einfach abfragen.

In der Powershell können dafür zwei Aufruf für das Testen von REST Services aufgerufen werden:

  • Invoke-WebRequest (iwr/curl/wget) ⇒ Alle Details , gut zum Debug
  • Invoke-RestMethod (irm) ⇒ Genau die Anwort des Service, gut für die Integration von REST Aufrufen in eigene Skripte

Invoke-WebRequest

curl/wget sind als Alias für das cmdlet „Invoke-WebRequest“ hinterlegt.

Beispiel für einen sehr einfachen REST Aufruf mit GET um die Version der API abzufragen:

Invoke-WebRequest -Uri http://127.0.0.1:9090/ords/gpi/api/version/
 
 
StatusCode        : 200
StatusDescription : OK
Content           : {"version":"1"}
RawContent        : HTTP/1.1 200 OK
                    Transfer-Encoding: chunked
                    Content-Type: application/json
                    Date: Sun, 21 Oct 2018 16:31:26 GMT
                    ETag: "Aj/F2I7I9tJv0HnVQVyQNka0ylNOD1DCJwMt77AHjZzC59+Udn0CKuCUb0NwiXOcT3nwWkl0nUj+Pyc...
Forms             : {}
Headers           : {[Transfer-Encoding, chunked], [Content-Type, application/json], [Date, Sun, 21 Oct 2018 16:31:26 GMT], [ETag,
                    "Aj/F2I7I9tJv0HnVQVyQNka0ylNOD1DCJwMt77AHjZzC59+Udn0CKuCUb0NwiXOcT3nwWkl0nUj+Pyc4zMU0Ow=="]}
Images            : {}
InputFields       : {}
Links             : {}
ParsedHtml        : mshtml.HTMLDocumentClass
RawContentLength  : 15

Invoke-RestMethod

In der Powershell steht einem dafür „Invoke-RestMethod“ bzw als alias „irm“ zur Verfügung.

Beispiel für einen sehr einfachen REST Aufruf mit GET um die Version der API abzufragen:

Invoke-RestMethod -Uri http:\\localhost:9090  
 
version
-------
1

REST Service abfragen

Beim Abfragen eines Webservice, zum Beispiel vom ORDS ⇒ Oracle ORDS 3.0 REST API nativ verwenden ist die Verwendung dieses Befehls sehr praktisch, ein Json Record wird gleich als Tabelle dargestellt.

irm -Uri http://127.0.0.1:9090/ords/gpi/api/version/
 
version
-------
1

Optionen

Invoke-RestMethod bzw. irm

help irm
 
NAME
    Invoke-RestMethod
 
SYNTAX
    Invoke-RestMethod [-Uri] <uri> [-Method {Default | Get | Head | Post | Put | Delete | Trace | Options | Merge | Patch}] [-UseBasicParsing] [-WebSession <WebRequestSession>] [-SessionVariable <string>]
    [-Credential <pscredential>] [-UseDefaultCredentials] [-CertificateThumbprint <string>] [-Certificate <X509Certificate>] [-UserAgent <string>] [-DisableKeepAlive] [-TimeoutSec <int>] [-Headers <IDictionary>]
    [-MaximumRedirection <int>] [-Proxy <uri>] [-ProxyCredential <pscredential>] [-ProxyUseDefaultCredentials] [-Body <Object>] [-ContentType <string>] [-TransferEncoding {chunked | compress | deflate | gzip |
    identity}] [-InFile <string>] [-OutFile <string>] [-PassThru]  [<CommonParameters>]
 
 
ALIASES
    irm
 
 
REMARKS
    Get-Help cannot find the Help files for this cmdlet on this computer. It is displaying only partial help.
        -- To download and install Help files for the module that includes this cmdlet, use Update-Help.
        -- To view the Help topic for this cmdlet online, type: "Get-Help Invoke-RestMethod -Online" or
           go to https://go.microsoft.com/fwlink/?LinkID=217034.

Invoke-WebRequest bzw. curl/wegt

help curl
 
NAME
    Invoke-WebRequest
 
SYNTAX
    Invoke-WebRequest [-Uri] <uri> [-UseBasicParsing] [-WebSession <WebRequestSession>] [-SessionVariable <string>] [-Credential <pscredential>] [-UseDefaultCredentials] [-CertificateThumbprint <string>]
    [-Certificate <X509Certificate>] [-UserAgent <string>] [-DisableKeepAlive] [-TimeoutSec <int>] [-Headers <IDictionary>] [-MaximumRedirection <int>] [-Method {Default | Get | Head | Post | Put | Delete | Trace |
    Options | Merge | Patch}] [-Proxy <uri>] [-ProxyCredential <pscredential>] [-ProxyUseDefaultCredentials] [-Body <Object>] [-ContentType <string>] [-TransferEncoding {chunked | compress | deflate | gzip |
    identity}] [-InFile <string>] [-OutFile <string>] [-PassThru]  [<CommonParameters>]
 
 
ALIASES
    iwr
    wget
    curl
 
 
REMARKS
    Get-Help cannot find the Help files for this cmdlet on this computer. It is displaying only partial help.
        -- To download and install Help files for the module that includes this cmdlet, use Update-Help.
        -- To view the Help topic for this cmdlet online, type: "Get-Help Invoke-WebRequest -Online" or
           go to https://go.microsoft.com/fwlink/?LinkID=217035.

Quellen

Diese Website verwendet Cookies. Durch die Nutzung der Website stimmen Sie dem Speichern von Cookies auf Ihrem Computer zu. Außerdem bestätigen Sie, dass Sie unsere Datenschutzbestimmungen gelesen und verstanden haben. Wenn Sie nicht einverstanden sind, verlassen Sie die Website.Weitere Information
windows/powershell_irm_curl_wget.txt · Zuletzt geändert: 2018/10/21 18:35 von gpipperr