$Form = @{
tags = 'Vacation', 'Italy', '2017'
pictures = Get-ChildItem 'C:\Users\jdoe\Pictures\2017-Italy\'
In the above example, the tags
field is supplied three times in the form, once for each of the
values: Vacation
, Italy
, and 2017
. The pictures
field is submitted once for each file in the
2017-Italy
folder. The binary contents of the files in that folder are submitted as the values.
This feature was added in PowerShell 6.1.0.
类型:IDictionary
默认值:None
支持通配符:False
不显示:False
(All)
Specifies the headers of the web request. Enter a hash table or dictionary.
Content related headers, such as Content-Type
are overridden when a MultipartFormDataContent
object is supplied for Body.
Starting in PowerShell 7.4, if you use this parameter to define the Content-Type
header and use
ContentType parameter, the value specified in the ContentType parameter is used.
类型:IDictionary
默认值:None
支持通配符:False
不显示:False
(All)
-HttpVersion
Specifies the HTTP version used for the request. The default is 1.1
.
Valid values are:
类型:Version
默认值:None
支持通配符:False
不显示:False
(All)
-InFile
Gets the content of the web request body from a file. Enter a path and filename. If you omit the
path, the default is the current location.
You also need to set the content type of the request. For example, to upload a file you should set
the content type. Usually, the type should be application/octet-stream
. However, you need to set
the content type based on the requirements of the endpoint.
类型:String
默认值:None
支持通配符:False
不显示:False
(All)
-MaximumFollowRelLink
Specifies how many times to follow relation links if FollowRelLink is used. A smaller value may
be needed if the REST api throttles due to too many requests. The default value is
[int32]::MaxValue
. A value of 0 (zero) prevents following relation links.
类型:Int32
默认值:Int32.MaxValue
支持通配符:False
不显示:False
别名:ML
(All)
-MaximumRedirection
Specifies how many times PowerShell redirects a connection to an alternate Uniform Resource
Identifier (URI) before the connection fails. The default value is 5. A value of 0 (zero) prevents
all redirection.
类型:Int32
默认值:None
支持通配符:False
不显示:False
(All)
-MaximumRetryCount
Specifies how many times PowerShell retries a connection when a failure code between 400 and 599,
inclusive or 304 is received. Also see RetryIntervalSec parameter for specifying the interval
between retries.
类型:Int32
默认值:None
支持通配符:False
不显示:False
(All)
-Method
Specifies the method used for the web request. The acceptable values for this parameter are:
Default
Delete
Merge
Options
Patch
Trace
The CustomMethod parameter can be used for Request Methods not listed above.
类型:WebRequestMethod
默认值:None
接受的值:Default, Get, Head, Post, Put, Delete, Trace, Options, Merge, Patch
支持通配符:False
不显示:False
StandardMethod
-NoProxy
Indicates that the cmdlet won't use a proxy to reach the destination. Use this to bypass the proxy
configured in your internet settings or specified in the environment.
This parameter was introduced in PowerShell 6.0.
类型:SwitchParameter
默认值:False
支持通配符:False
不显示:False
StandardMethodNoProxy
-OperationTimeoutSeconds
This timeout applies to data reads within a stream, not to the stream time as a whole. The default
value, 0, specifies an indefinite timeout.
Setting the value to 30 seconds means that any delay of longer than 30 seconds between data in the
stream terminates the request. A large file that takes several minutes to download won't terminate
unless the stream stalls for more than 30 seconds.
类型:Int32
默认值:None
支持通配符:False
不显示:False
(All)
-OutFile
By default, Invoke-RestMethod
returns the results to the pipeline. When you use the OutFile
parameter, the results are saved to the specified file and not returned to the pipeline. Enter a
path and filename. To send the results to a file and to the pipeline, add the PassThru
parameter.
If you omit the path, the default is the current location. The name is treated as a literal path.
Names that contain brackets ([]
) must be enclosed in single quotes ('
).
Starting in PowerShell 7.4, you can specify a folder path without the filename. When you do, the
command uses filename from the last segment of the resolved URI after any redirections. When you
specify a folder path for OutFile, you can't use the Resume parameter.
类型:String
默认值:None
支持通配符:False
不显示:False
(All)
-PassThru
This parameter is valid only when the OutFile parameter is also used in the command. The intent
is to have the results written to the file and to the pipeline.
类型:SwitchParameter
默认值:No output
支持通配符:False
不显示:False
(All)
-PreserveAuthorizationOnRedirect
Indicates the cmdlet should preserve the Authorization
header, when present, across redirections.
By default, the cmdlet strips the Authorization
header before redirecting. Specifying this
parameter disables this logic for cases where the header needs to be sent to the redirection
location.
This feature was added in PowerShell 6.0.0.
类型:SwitchParameter
默认值:False
支持通配符:False
不显示:False
(All)
-PreserveHttpMethodOnRedirect
Indicates the cmdlet should preserve the method of the request across redirections.
By default, the cmdlet changes the method to GET
when redirected. Specifying this parameter
disables this logic to ensure that the intended method can be used with redirection.
This feature was added in PowerShell 7.4.
类型:SwitchParameter
默认值:False
支持通配符:False
不显示:False
(All)
-Proxy
Uses a proxy server for the request, rather than connecting directly to the internet resource. Enter
the Uniform Resource Identifier (URI) of a network proxy server.
This feature was added in PowerShell 6.0.0.
类型:Uri
默认值:None
支持通配符:False
不显示:False
StandardMethod
-ProxyCredential
Specifies a user account that has permission to use the proxy server that's specified by the
Proxy parameter. The default is the current user.
Type a user name, such as "User01" or "Domain01\User01", or enter a PSCredential object, such
as one generated by the Get-Credential
cmdlet.
This parameter is valid only when the Proxy parameter is also used in the command. You can't use
the ProxyCredential and ProxyUseDefaultCredentials parameters in the same command.
类型:PSCredential
默认值:None
支持通配符:False
不显示:False
StandardMethod
-ProxyUseDefaultCredentials
Uses the credentials of the current user to access the proxy server that is specified by the
Proxy parameter.
This parameter is valid only when the Proxy parameter is also used in the command. You can't use
the ProxyCredential and ProxyUseDefaultCredentials parameters in the same command.
类型:SwitchParameter
默认值:False
支持通配符:False
不显示:False
StandardMethod
Creates a variable containing a Response Headers Dictionary. Enter a variable name without the
dollar sign ($
) symbol. The keys of the dictionary contain the field names and values of the
Response Header returned by the web server.
This feature was added in PowerShell 6.0.0.
类型:String
默认值:None
支持通配符:False
不显示:False
别名:RHV
(All)
-Resume
Performs a best effort attempt to resume downloading a partial file. The Resume parameter
requires the OutFile parameter.
Resume only operates on the size of the local file and remote file and performs no other
validation that the local file and the remote file are the same.
If the local file size is smaller than the remote file size, then the cmdlet attempts to resume
downloading the file and append the remaining bytes to the end of the file.
If the local file size is the same as the remote file size, then no action is taken and the cmdlet
assumes the download already completed.
If the local file size is larger than the remote file size, then the local file is overwritten and
the entire remote file is re-downloaded. This behavior is the same as using OutFile without
Resume.
If the remote server doesn't support download resuming, then the local file is overwritten and the
entire remote file is re-downloaded. This behavior is the same as using OutFile without
Resume.
If the local file doesn't exist, then the local file is created and the entire remote file is
downloaded. This behavior is the same as using OutFile without Resume.
This feature was added in PowerShell 6.1.0.
类型:SwitchParameter
默认值:False
支持通配符:False
不显示:False
(All)
-RetryIntervalSec
Specifies the interval between retries for the connection when a failure code between 400 and 599,
inclusive or 304 is received. The value must be between 1
and [int]::MaxValue
.
When the failure code is 429 and the response includes the Retry-After property in its headers,
the cmdlet uses that value for the retry interval, even if this parameter is specified.
Also, see the MaximumRetryCount parameter for specifying number of retries.
类型:Int32
默认值:5
支持通配符:False
不显示:False
(All)
-SessionVariable
Creates a variable containing the web request session. Enter a variable name without the dollar sign
($
) symbol.
When you specify a session variable, Invoke-RestMethod
creates a web request session object and
assigns it to a variable with the specified name in your PowerShell session. You can use the
variable in your session as soon as the command completes.
Before PowerShell 7.4, the web request session isn't a persistent connection. It's an object that
contains information about the connection and the request, including cookies, credentials, the
maximum redirection value, and the user agent string. You can use it to share state and data among
web requests.
Starting in PowerShell 7.4, the web request session is persistent as long as the properties of the
session aren't overridden in a subsequent request. When they are, the cmdlet recreates the session
with the new values. The persistent sessions reduce the overhead for repeated requests, making them
much faster.
To use the web request session in subsequent web requests, specify the session variable in the value
of the WebSession parameter. PowerShell uses the data in the web request session object when
establishing the new connection. To override a value in the web request session, use a cmdlet
parameter, such as UserAgent or Credential. Parameter values take precedence over values in
the web request session.
You can't use the SessionVariable and WebSession parameters in the same command.
类型:String
默认值:None
支持通配符:False
不显示:False
别名:SV
(All)
-SkipCertificateCheck
Skips certificate validation checks that include all validations such as expiration, revocation,
trusted root authority, etc.
Warning
Using this parameter isn't secure and isn't recommended. This switch is only intended to be used
against known hosts using a self-signed certificate for testing purposes. Use at your own risk.
This feature was added in PowerShell 6.0.0.
类型:SwitchParameter
默认值:False
支持通配符:False
不显示:False
(All)
Indicates the cmdlet should add headers to the request without validation.
This switch should be used for sites that require header values that don't conform to standards.
Specifying this switch disables validation to allow the value to be passed unchecked. When
specified, all headers are added without validation.
This switch disables validation for values passed to the ContentType, Headers, and
UserAgent parameters.
This feature was added in PowerShell 6.0.0.
类型:SwitchParameter
默认值:False
支持通配符:False
不显示:False
(All)
-SkipHttpErrorCheck
This parameter causes the cmdlet to ignore HTTP error statuses and continue to process responses.
The error responses are written to the pipeline just as if they were successful.
This parameter was introduced in PowerShell 7.
类型:SwitchParameter
默认值:False
支持通配符:False
不显示:False
(All)
-SslProtocol
Sets the SSL/TLS protocols that are permissible for the web request. By default all, SSL/TLS
protocols supported by the system are allowed. SslProtocol allows for limiting to specific
protocols for compliance purposes.
These values are defined as a flag-based enumeration. You can combine multiple values together to
set multiple flags using this parameter. The values can be passed to the SslProtocol parameter
as an array of values or as a comma-separated string of those values. The cmdlet combines the values
using a binary-OR operation. Passing values as an array is the simplest option and also allows you
to use tab-completion on the values. You may not be able to supply multiple values on all platforms.
This feature was added in PowerShell 6.0.0. Support for Tls13
was added in PowerShell 7.1.
类型:WebSslProtocol
默认值:None
接受的值:Default, Tls, Tls11, Tls12, Tls13
支持通配符:False
不显示:False
(All)
-StatusCodeVariable
Creates a variable containing a HTTP status code result of the request. Enter a variable name
without the dollar sign ($
) symbol.
The parameter can identify success messages or failure messages when used with the
SkipHttpErrorCheck parameter.
Input the parameter's variable name as a string such as -StatusCodeVariable "scv"
.
This parameter was introduced in PowerShell 7.
类型:String
默认值:None
支持通配符:False
不显示:False
(All)
-Token
The OAuth or Bearer token to include in the request. Token is required by certain
Authentication options. It can't be used independently.
Token takes a SecureString
that contains the token. To supply the token, manually use the
following:
Invoke-RestMethod -Uri $uri -Authentication OAuth -Token (Read-Host -AsSecureString)
This parameter was introduced in PowerShell 6.0.
类型:SecureString
默认值:None
支持通配符:False
不显示:False
(All)
-TransferEncoding
Specifies a value for the transfer-encoding HTTP response header. The acceptable values for this
parameter are:
Chunked
Compress
Deflate
Identity
类型:String
默认值:None
接受的值:chunked, compress, deflate, gzip, identity
支持通配符:False
不显示:False
(All)
-UnixSocket
Specifies the name of the Unix socket to connect to. This parameter is supported on Unix-based
systems and Windows version 1803 and later. For more information about Windows support of Unix
sockets, see the
Windows/WSL Interop with AF_UNIX
blog post.
This parameter was added in PowerShell 7.4.
类型:UnixDomainSocketEndPoint
默认值:None
支持通配符:False
不显示:False
(All)
Specifies the Uniform Resource Identifier (URI) of the internet resource to which the web request is
sent. This parameter supports HTTP, HTTPS, FTP, and FILE values.
This parameter is required. The parameter name (Uri) is optional.
类型:Uri
默认值:None
支持通配符:False
不显示:False
(All)
-UseBasicParsing
This parameter has been deprecated. Beginning with PowerShell 6.0.0, all Web requests use basic
parsing only. This parameter is included for backwards compatibility only. When used, it has no
effect on the operation of the cmdlet.
类型:SwitchParameter
默认值:False
支持通配符:False
不显示:False
(All)
-UseDefaultCredentials
Indicates that the cmdlet uses the credentials of the current user to send the web request. This
can't be used with Authentication or Credential and may not be supported on all platforms.
类型:SwitchParameter
默认值:False
支持通配符:False
不显示:False
(All)
-UserAgent
Specifies a user agent string for the web request.
The default user agent is similar to
Mozilla/5.0 (Windows NT 10.0; Microsoft Windows 10.0.15063; en-US) PowerShell/6.0.0
with slight
variations for each operating system and platform.
To test a website with the standard user agent string that's used by most internet browsers, use
the properties of the PSUserAgent class, such as
Chrome, Firefox, InternetExplorer, Opera, and Safari.
类型:String
默认值:None
支持通配符:False
不显示:False
(All)
-WebSession
Specifies a web request session. Enter the variable name, including the dollar sign ($
).
To override a value in the web request session, use a cmdlet parameter, such as UserAgent or
Credential. Parameter values take precedence over values in the web request session. Content
related headers, such as Content-Type
, are overridden when a MultipartFormDataContent object
is supplied for Body.
Unlike a remote session, the web request session isn't a persistent connection. It's an object that
contains information about the connection and the request, including cookies, credentials, the
maximum redirection value, and the user agent string. You can use it to share state and data among
web requests.
To create a web request session, enter a variable name, without a dollar sign, in the value of the
SessionVariable parameter of an Invoke-RestMethod
command. Invoke-RestMethod
creates the
session and saves it in the variable. In subsequent commands, use the variable as the value of the
WebSession parameter.
You can't use the SessionVariable and WebSession parameters in the same command.
类型:WebRequestSession
默认值:None
支持通配符:False
不显示:False
(All)
CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable,
-InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable,
-ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see
about_CommonParameters.
You can pipe the body of a web request to this cmdlet.
When the request returns an integer, this cmdlet returns that integer.
When the request returns a string, this cmdlet returns that string.
When the request returns valid XML, this cmdlet returns it as an XmlDocument.
PSObject
When the request returns JSON strings, this cmdlet returns a PSObject representing the data.
PowerShell includes the following aliases for Invoke-RestMethod
:
All platforms:
Some features may not be available on all platforms.
Because of changes in .NET Core 3.1, PowerShell 7.0 and higher use the
HttpClient.DefaultProxy property to determine the
proxy configuration.
The value of this property differ depending on your platform:
For Windows: Reads proxy configuration from environment variables or, if those aren't defined,
from the user's proxy settings.
For macOS: Reads proxy configuration from environment variables or, if those aren't defined,
from the system's proxy settings.
For Linux: Reads proxy configuration from environment variables or, in case those aren't
defined, this property initializes a non-configured instance that bypasses all addresses.
The environment variables used for DefaultProxy
initialization on Windows and Unix-based platforms
HTTP_PROXY
: the hostname or IP address of the proxy server used on HTTP requests.
HTTPS_PROXY
: the hostname or IP address of the proxy server used on HTTPS requests.
ALL_PROXY
: the hostname or IP address of the proxy server used on HTTP and HTTPS requests in
case HTTP_PROXY
or HTTPS_PROXY
aren't defined.
NO_PROXY
: a comma-separated list of hostnames that should be excluded from proxying.
PowerShell 7.4 added support for the Brotli compression algorithm.
ConvertTo-Json
ConvertFrom-Json
Invoke-WebRequest