PowerShellHttpModule.dll-Help.xml
<?xml version="1.0" encoding="utf-8"?>
<helpItems schema="maml" xmlns="http://msh"> <!-- Cmdlet: Get-HttpListener --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name>Get-HttpListener</command:name> <command:verb>Get</command:verb> <command:noun>HttpListener</command:noun> <maml:description> <maml:para>Gets all the created HttpListener objects.</maml:para> </maml:description> </command:details> <maml:description> <maml:para>Gets all created HttpListener objects through this module's Cmdlets, regardless of if they are still active or not.</maml:para> </maml:description> <command:syntax> <!-- Parameter set: __AllParameterSets --> <command:syntaxItem> <maml:name>Get-HttpListener</maml:name> </command:syntaxItem> </command:syntax> <command:parameters /> <command:inputTypes /> <command:returnValues> <!-- OutputType: HttpListener --> <command:returnValue> <dev:type> <maml:name>System.Net.HttpListener</maml:name> <maml:uri /> </dev:type> </command:returnValue> </command:returnValues> <command:examples> <command:example> <maml:title>---------- EXAMPLE 1 ----------</maml:title> <maml:introduction> <maml:para>Submits Single Response</maml:para> </maml:introduction> <dev:code>try { 'http://localhost/api' | New-HttpListener -AuthenticationSchemes Basic | Start-HttpListener | Wait-HttpRequest -Count 1 | ForEach-Object { $request = $_ | Receive-HttpRequest | ConvertFrom-Json @{Message="Hello $($request.Name)"} | ConvertTo-Json | Submit-HttpResponse -Request $_ } } finally { Get-HttpListener | Stop-HttpListener }</dev:code> <dev:remarks> <maml:para>Call from *another* shell:</maml:para> <maml:para>$cred = Get-Credential -Message "For PowerShell-REST" -UserName "$ENV:COMPUTERNAME\$ENV:USERNAME" Invoke-RestMethod -Method Post -Uri 'http://localhost/api' -Body $(@{Name='test'} | ConvertTo-Json) -ContentType 'application/json' -Authentication Basic -Credential $cred -AllowUnencryptedAuthentication</maml:para> </dev:remarks> </command:example> <command:example> <maml:title>---------- EXAMPLE 2 ----------</maml:title> <maml:introduction> <maml:para>Submits Indefinite Responses</maml:para> </maml:introduction> <dev:code>try { 'http://localhost/api' | New-HttpListener -AuthenticationSchemes Basic | Start-HttpListener | Wait-HttpRequest -Infinity | ForEach-Object { $request = $_ | Receive-HttpRequest | ConvertFrom-Json @{Message="Hello $($request.Name)"} | ConvertToJson | Submit-HttpResponse -Request $_ } } finally { Get-HttpListener | Stop-HttpListener }</dev:code> <dev:remarks> <maml:para>Call from *another* shell:</maml:para> <maml:para>$cred = Get-Credential -Message "For PowerShell-REST" -UserName "$ENV:COMPUTERNAME\$ENV:USERNAME" Invoke-RestMethod -Method Post -Uri 'http://localhost/api' -Body $(@{Name='test'} | ConvertTo-Json) -ContentType 'application/json' -Authentication Basic -Credential $cred -AllowUnencryptedAuthentication</maml:para> </dev:remarks> </command:example> <command:example> <maml:title>---------- EXAMPLE 3 ----------</maml:title> <maml:introduction> <maml:para>Denies Single Response</maml:para> </maml:introduction> <dev:code>try { 'http://localhost/api' | New-HttpListener -AuthenticationSchemes Basic | Start-HttpListener | Wait-HttpRequest -Count 1 | ForEach-Object { $request = $_ | Receive-HttpRequest | ConvertFrom-Json Deny-HttpResponse -Request $_ } } finally { Get-HttpListener | Stop-HttpListener }</dev:code> <dev:remarks> <maml:para>Call from *another* shell:</maml:para> <maml:para>$cred = Get-Credential -Message "For PowerShell-REST" -UserName "$ENV:COMPUTERNAME\$ENV:USERNAME" Invoke-RestMethod -Method Post -Uri 'http://localhost/api' -Body $(@{Name='test'} | ConvertTo-Json) -ContentType 'application/json' -Authentication Basic -Credential $cred -AllowUnencryptedAuthentication</maml:para> </dev:remarks> </command:example> </command:examples> </command:command> <!-- Cmdlet: New-HttpListener --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name>New-HttpListener</command:name> <command:verb>New</command:verb> <command:noun>HttpListener</command:noun> <maml:description> <maml:para>Creates a new HttpListener object.</maml:para> </maml:description> </command:details> <maml:description> <maml:para>HttpListener objects are used to listen for client requests.</maml:para> </maml:description> <command:syntax> <!-- Parameter set: __AllParameterSets --> <command:syntaxItem> <maml:name>New-HttpListener</maml:name> <!-- Parameter: UriPrefix --> <command:parameter required="true" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>UriPrefix</maml:name> <maml:description> <maml:para>URI prefixes that the HttpListener will listen for.</maml:para> <maml:para>This specifies a root URI whereby the HttpListener will respond to any URI under its path.</maml:para> </maml:description> <command:parameterValue required="true">string</command:parameterValue> <dev:type> <maml:name>System.String</maml:name> <maml:uri /> </dev:type> </command:parameter> <!-- Parameter: AuthenticationSchemes --> <command:parameter required="false" globbing="false" pipelineInput="false" position="named"> <maml:name>AuthenticationSchemes</maml:name> <maml:description> <maml:para>Declare how a user can Authenticate.</maml:para> <maml:para>Possible values: None, Digest, Negotiate, Ntlm, Basic, Anonymous, IntegratedWindowsAuthentication</maml:para> </maml:description> <command:parameterValue required="true">AuthenticationSchemes[]</command:parameterValue> <dev:type> <maml:name>System.Net.AuthenticationSchemes[]</maml:name> <maml:uri /> </dev:type> <command:parameterValueGroup> <command:parameterValue required="false" variableLength="false">None</command:parameterValue> <command:parameterValue required="false" variableLength="false">Digest</command:parameterValue> <command:parameterValue required="false" variableLength="false">Negotiate</command:parameterValue> <command:parameterValue required="false" variableLength="false">Ntlm</command:parameterValue> <command:parameterValue required="false" variableLength="false">Basic</command:parameterValue> <command:parameterValue required="false" variableLength="false">Anonymous</command:parameterValue> <command:parameterValue required="false" variableLength="false">IntegratedWindowsAuthentication</command:parameterValue> </command:parameterValueGroup> </command:parameter> </command:syntaxItem> </command:syntax> <command:parameters> <!-- Parameter: UriPrefix --> <command:parameter required="true" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>UriPrefix</maml:name> <maml:description> <maml:para>URI prefixes that the HttpListener will listen for.</maml:para> <maml:para>This specifies a root URI whereby the HttpListener will respond to any URI under its path.</maml:para> </maml:description> <command:parameterValue required="true">string</command:parameterValue> <dev:type> <maml:name>System.String</maml:name> <maml:uri /> </dev:type> </command:parameter> <!-- Parameter: AuthenticationSchemes --> <command:parameter required="false" globbing="false" pipelineInput="false" position="named"> <maml:name>AuthenticationSchemes</maml:name> <maml:description> <maml:para>Declare how a user can Authenticate.</maml:para> <maml:para>Possible values: None, Digest, Negotiate, Ntlm, Basic, Anonymous, IntegratedWindowsAuthentication</maml:para> </maml:description> <command:parameterValue required="true">AuthenticationSchemes[]</command:parameterValue> <dev:type> <maml:name>System.Net.AuthenticationSchemes[]</maml:name> <maml:uri /> </dev:type> <command:parameterValueGroup> <command:parameterValue required="false" variableLength="false">None</command:parameterValue> <command:parameterValue required="false" variableLength="false">Digest</command:parameterValue> <command:parameterValue required="false" variableLength="false">Negotiate</command:parameterValue> <command:parameterValue required="false" variableLength="false">Ntlm</command:parameterValue> <command:parameterValue required="false" variableLength="false">Basic</command:parameterValue> <command:parameterValue required="false" variableLength="false">Anonymous</command:parameterValue> <command:parameterValue required="false" variableLength="false">IntegratedWindowsAuthentication</command:parameterValue> </command:parameterValueGroup> </command:parameter> </command:parameters> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.String</maml:name> <maml:uri /> </dev:type> <maml:description> <maml:para>URI prefixes that the HttpListener will listen for.</maml:para> <maml:para>This specifies a root URI whereby the HttpListener will respond to any URI under its path.</maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <!-- OutputType: HttpListener --> <command:returnValue> <dev:type> <maml:name>System.Net.HttpListener</maml:name> <maml:uri /> </dev:type> </command:returnValue> </command:returnValues> <command:examples> <command:example> <maml:title>---------- EXAMPLE 1 ----------</maml:title> <maml:introduction> <maml:para>Submits Single Response</maml:para> </maml:introduction> <dev:code>try { 'http://localhost/api' | New-HttpListener -AuthenticationSchemes Basic | Start-HttpListener | Wait-HttpRequest -Count 1 | ForEach-Object { $request = $_ | Receive-HttpRequest | ConvertFrom-Json @{Message="Hello $($request.Name)"} | ConvertTo-Json | Submit-HttpResponse -Request $_ } } finally { Get-HttpListener | Stop-HttpListener }</dev:code> <dev:remarks> <maml:para>Call from *another* shell:</maml:para> <maml:para>$cred = Get-Credential -Message "For PowerShell-REST" -UserName "$ENV:COMPUTERNAME\$ENV:USERNAME" Invoke-RestMethod -Method Post -Uri 'http://localhost/api' -Body $(@{Name='test'} | ConvertTo-Json) -ContentType 'application/json' -Authentication Basic -Credential $cred -AllowUnencryptedAuthentication</maml:para> </dev:remarks> </command:example> <command:example> <maml:title>---------- EXAMPLE 2 ----------</maml:title> <maml:introduction> <maml:para>Submits Indefinite Responses</maml:para> </maml:introduction> <dev:code>try { 'http://localhost/api' | New-HttpListener -AuthenticationSchemes Basic | Start-HttpListener | Wait-HttpRequest -Infinity | ForEach-Object { $request = $_ | Receive-HttpRequest | ConvertFrom-Json @{Message="Hello $($request.Name)"} | ConvertToJson | Submit-HttpResponse -Request $_ } } finally { Get-HttpListener | Stop-HttpListener }</dev:code> <dev:remarks> <maml:para>Call from *another* shell:</maml:para> <maml:para>$cred = Get-Credential -Message "For PowerShell-REST" -UserName "$ENV:COMPUTERNAME\$ENV:USERNAME" Invoke-RestMethod -Method Post -Uri 'http://localhost/api' -Body $(@{Name='test'} | ConvertTo-Json) -ContentType 'application/json' -Authentication Basic -Credential $cred -AllowUnencryptedAuthentication</maml:para> </dev:remarks> </command:example> <command:example> <maml:title>---------- EXAMPLE 3 ----------</maml:title> <maml:introduction> <maml:para>Denies Single Response</maml:para> </maml:introduction> <dev:code>try { 'http://localhost/api' | New-HttpListener -AuthenticationSchemes Basic | Start-HttpListener | Wait-HttpRequest -Count 1 | ForEach-Object { $request = $_ | Receive-HttpRequest | ConvertFrom-Json Deny-HttpResponse -Request $_ } } finally { Get-HttpListener | Stop-HttpListener }</dev:code> <dev:remarks> <maml:para>Call from *another* shell:</maml:para> <maml:para>$cred = Get-Credential -Message "For PowerShell-REST" -UserName "$ENV:COMPUTERNAME\$ENV:USERNAME" Invoke-RestMethod -Method Post -Uri 'http://localhost/api' -Body $(@{Name='test'} | ConvertTo-Json) -ContentType 'application/json' -Authentication Basic -Credential $cred -AllowUnencryptedAuthentication</maml:para> </dev:remarks> </command:example> </command:examples> </command:command> <!-- Cmdlet: Start-HttpListener --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name>Start-HttpListener</command:name> <command:verb>Start</command:verb> <command:noun>HttpListener</command:noun> <maml:description> <maml:para>Starts listening for client requests.</maml:para> </maml:description> </command:details> <maml:description> <maml:para>Allows this instance to receive incoming requests.</maml:para> </maml:description> <command:syntax> <!-- Parameter set: __AllParameterSets --> <command:syntaxItem> <maml:name>Start-HttpListener</maml:name> <!-- Parameter: Listener --> <command:parameter required="true" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>Listener</maml:name> <maml:description> <maml:para>Used to listen for client requests.</maml:para> </maml:description> <command:parameterValue required="true">HttpListener</command:parameterValue> <dev:type> <maml:name>System.Net.HttpListener</maml:name> <maml:uri /> </dev:type> </command:parameter> </command:syntaxItem> </command:syntax> <command:parameters> <!-- Parameter: Listener --> <command:parameter required="true" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>Listener</maml:name> <maml:description> <maml:para>Used to listen for client requests.</maml:para> </maml:description> <command:parameterValue required="true">HttpListener</command:parameterValue> <dev:type> <maml:name>System.Net.HttpListener</maml:name> <maml:uri /> </dev:type> </command:parameter> </command:parameters> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.Net.HttpListener</maml:name> <maml:uri /> </dev:type> <maml:description> <maml:para>Used to listen for client requests.</maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <!-- OutputType: HttpListener --> <command:returnValue> <dev:type> <maml:name>System.Net.HttpListener</maml:name> <maml:uri /> </dev:type> </command:returnValue> </command:returnValues> <command:examples> <command:example> <maml:title>---------- EXAMPLE 1 ----------</maml:title> <maml:introduction> <maml:para>Submits Single Response</maml:para> </maml:introduction> <dev:code>try { 'http://localhost/api' | New-HttpListener -AuthenticationSchemes Basic | Start-HttpListener | Wait-HttpRequest -Count 1 | ForEach-Object { $request = $_ | Receive-HttpRequest | ConvertFrom-Json @{Message="Hello $($request.Name)"} | ConvertTo-Json | Submit-HttpResponse -Request $_ } } finally { Get-HttpListener | Stop-HttpListener }</dev:code> <dev:remarks> <maml:para>Call from *another* shell:</maml:para> <maml:para>$cred = Get-Credential -Message "For PowerShell-REST" -UserName "$ENV:COMPUTERNAME\$ENV:USERNAME" Invoke-RestMethod -Method Post -Uri 'http://localhost/api' -Body $(@{Name='test'} | ConvertTo-Json) -ContentType 'application/json' -Authentication Basic -Credential $cred -AllowUnencryptedAuthentication</maml:para> </dev:remarks> </command:example> <command:example> <maml:title>---------- EXAMPLE 2 ----------</maml:title> <maml:introduction> <maml:para>Submits Indefinite Responses</maml:para> </maml:introduction> <dev:code>try { 'http://localhost/api' | New-HttpListener -AuthenticationSchemes Basic | Start-HttpListener | Wait-HttpRequest -Infinity | ForEach-Object { $request = $_ | Receive-HttpRequest | ConvertFrom-Json @{Message="Hello $($request.Name)"} | ConvertToJson | Submit-HttpResponse -Request $_ } } finally { Get-HttpListener | Stop-HttpListener }</dev:code> <dev:remarks> <maml:para>Call from *another* shell:</maml:para> <maml:para>$cred = Get-Credential -Message "For PowerShell-REST" -UserName "$ENV:COMPUTERNAME\$ENV:USERNAME" Invoke-RestMethod -Method Post -Uri 'http://localhost/api' -Body $(@{Name='test'} | ConvertTo-Json) -ContentType 'application/json' -Authentication Basic -Credential $cred -AllowUnencryptedAuthentication</maml:para> </dev:remarks> </command:example> <command:example> <maml:title>---------- EXAMPLE 3 ----------</maml:title> <maml:introduction> <maml:para>Denies Single Response</maml:para> </maml:introduction> <dev:code>try { 'http://localhost/api' | New-HttpListener -AuthenticationSchemes Basic | Start-HttpListener | Wait-HttpRequest -Count 1 | ForEach-Object { $request = $_ | Receive-HttpRequest | ConvertFrom-Json Deny-HttpResponse -Request $_ } } finally { Get-HttpListener | Stop-HttpListener }</dev:code> <dev:remarks> <maml:para>Call from *another* shell:</maml:para> <maml:para>$cred = Get-Credential -Message "For PowerShell-REST" -UserName "$ENV:COMPUTERNAME\$ENV:USERNAME" Invoke-RestMethod -Method Post -Uri 'http://localhost/api' -Body $(@{Name='test'} | ConvertTo-Json) -ContentType 'application/json' -Authentication Basic -Credential $cred -AllowUnencryptedAuthentication</maml:para> </dev:remarks> </command:example> </command:examples> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Citation.</maml:linkText> <maml:uri>https://docs.microsoft.com/en-us/dotnet/api/system.net.httplistener.start?view=net-5.0#System_Net_HttpListener_Start</maml:uri> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- Cmdlet: Stop-HttpListener --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name>Stop-HttpListener</command:name> <command:verb>Stop</command:verb> <command:noun>HttpListener</command:noun> <maml:description> <maml:para>Stops listening for client requests.</maml:para> </maml:description> </command:details> <maml:description> <maml:para>Causes this instance to stop receiving new incoming requests and terminates processing of all ongoing requests.</maml:para> </maml:description> <command:syntax> <!-- Parameter set: __AllParameterSets --> <command:syntaxItem> <maml:name>Stop-HttpListener</maml:name> <!-- Parameter: Listener --> <command:parameter required="true" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>Listener</maml:name> <maml:description> <maml:para>Used to listen for client requests.</maml:para> </maml:description> <command:parameterValue required="true">HttpListener</command:parameterValue> <dev:type> <maml:name>System.Net.HttpListener</maml:name> <maml:uri /> </dev:type> </command:parameter> </command:syntaxItem> </command:syntax> <command:parameters> <!-- Parameter: Listener --> <command:parameter required="true" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>Listener</maml:name> <maml:description> <maml:para>Used to listen for client requests.</maml:para> </maml:description> <command:parameterValue required="true">HttpListener</command:parameterValue> <dev:type> <maml:name>System.Net.HttpListener</maml:name> <maml:uri /> </dev:type> </command:parameter> </command:parameters> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.Net.HttpListener</maml:name> <maml:uri /> </dev:type> <maml:description> <maml:para>Used to listen for client requests.</maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues /> <command:examples> <command:example> <maml:title>---------- EXAMPLE 1 ----------</maml:title> <maml:introduction> <maml:para>Submits Single Response</maml:para> </maml:introduction> <dev:code>try { 'http://localhost/api' | New-HttpListener -AuthenticationSchemes Basic | Start-HttpListener | Wait-HttpRequest -Count 1 | ForEach-Object { $request = $_ | Receive-HttpRequest | ConvertFrom-Json @{Message="Hello $($request.Name)"} | ConvertTo-Json | Submit-HttpResponse -Request $_ } } finally { Get-HttpListener | Stop-HttpListener }</dev:code> <dev:remarks> <maml:para>Call from *another* shell:</maml:para> <maml:para>$cred = Get-Credential -Message "For PowerShell-REST" -UserName "$ENV:COMPUTERNAME\$ENV:USERNAME" Invoke-RestMethod -Method Post -Uri 'http://localhost/api' -Body $(@{Name='test'} | ConvertTo-Json) -ContentType 'application/json' -Authentication Basic -Credential $cred -AllowUnencryptedAuthentication</maml:para> </dev:remarks> </command:example> <command:example> <maml:title>---------- EXAMPLE 2 ----------</maml:title> <maml:introduction> <maml:para>Submits Indefinite Responses</maml:para> </maml:introduction> <dev:code>try { 'http://localhost/api' | New-HttpListener -AuthenticationSchemes Basic | Start-HttpListener | Wait-HttpRequest -Infinity | ForEach-Object { $request = $_ | Receive-HttpRequest | ConvertFrom-Json @{Message="Hello $($request.Name)"} | ConvertToJson | Submit-HttpResponse -Request $_ } } finally { Get-HttpListener | Stop-HttpListener }</dev:code> <dev:remarks> <maml:para>Call from *another* shell:</maml:para> <maml:para>$cred = Get-Credential -Message "For PowerShell-REST" -UserName "$ENV:COMPUTERNAME\$ENV:USERNAME" Invoke-RestMethod -Method Post -Uri 'http://localhost/api' -Body $(@{Name='test'} | ConvertTo-Json) -ContentType 'application/json' -Authentication Basic -Credential $cred -AllowUnencryptedAuthentication</maml:para> </dev:remarks> </command:example> <command:example> <maml:title>---------- EXAMPLE 3 ----------</maml:title> <maml:introduction> <maml:para>Denies Single Response</maml:para> </maml:introduction> <dev:code>try { 'http://localhost/api' | New-HttpListener -AuthenticationSchemes Basic | Start-HttpListener | Wait-HttpRequest -Count 1 | ForEach-Object { $request = $_ | Receive-HttpRequest | ConvertFrom-Json Deny-HttpResponse -Request $_ } } finally { Get-HttpListener | Stop-HttpListener }</dev:code> <dev:remarks> <maml:para>Call from *another* shell:</maml:para> <maml:para>$cred = Get-Credential -Message "For PowerShell-REST" -UserName "$ENV:COMPUTERNAME\$ENV:USERNAME" Invoke-RestMethod -Method Post -Uri 'http://localhost/api' -Body $(@{Name='test'} | ConvertTo-Json) -ContentType 'application/json' -Authentication Basic -Credential $cred -AllowUnencryptedAuthentication</maml:para> </dev:remarks> </command:example> </command:examples> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Citation.</maml:linkText> <maml:uri>https://docs.microsoft.com/en-us/dotnet/api/system.net.httplistener.stop?view=net-5.0#System_Net_HttpListener_Stop</maml:uri> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- Cmdlet: Receive-HttpRequest --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name>Receive-HttpRequest</command:name> <command:verb>Receive</command:verb> <command:noun>HttpRequest</command:noun> <maml:description> <maml:para>Retrieves the body of the HttpListenerRequest.</maml:para> </maml:description> </command:details> <maml:description> <maml:para>The body of the HttpListenerRequest, if it is JSON, is expected to be piped to the ConvertFrom-Json Cmdlet.</maml:para> </maml:description> <command:syntax> <!-- Parameter set: __AllParameterSets --> <command:syntaxItem> <maml:name>Receive-HttpRequest</maml:name> <!-- Parameter: Context --> <command:parameter required="true" globbing="false" pipelineInput="true (ByValue)" position="named" aliases="Request"> <maml:name>Context</maml:name> <maml:description> <maml:para>The HttpListenerContext that corresponds to the client request.</maml:para> </maml:description> <command:parameterValue required="true">HttpListenerContext</command:parameterValue> <dev:type> <maml:name>System.Net.HttpListenerContext</maml:name> <maml:uri /> </dev:type> </command:parameter> </command:syntaxItem> </command:syntax> <command:parameters> <!-- Parameter: Context --> <command:parameter required="true" globbing="false" pipelineInput="true (ByValue)" position="named" aliases="Request"> <maml:name>Context</maml:name> <maml:description> <maml:para>The HttpListenerContext that corresponds to the client request.</maml:para> </maml:description> <command:parameterValue required="true">HttpListenerContext</command:parameterValue> <dev:type> <maml:name>System.Net.HttpListenerContext</maml:name> <maml:uri /> </dev:type> </command:parameter> <command:parameter required="true" globbing="false" pipelineInput="true (ByValue)" position="named" aliases="Request"> <maml:name>Request</maml:name> <maml:description> <maml:para>The HttpListenerContext that corresponds to the client request.</maml:para> <maml:para>This is an alias of the Context parameter.</maml:para> </maml:description> <command:parameterValue required="true">HttpListenerContext</command:parameterValue> <dev:type> <maml:name>System.Net.HttpListenerContext</maml:name> <maml:uri /> </dev:type> </command:parameter> </command:parameters> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.Net.HttpListenerContext</maml:name> <maml:uri /> </dev:type> <maml:description> <maml:para>The HttpListenerContext that corresponds to the client request.</maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <!-- OutputType: String --> <command:returnValue> <dev:type> <maml:name>System.String</maml:name> <maml:uri /> </dev:type> </command:returnValue> </command:returnValues> <command:examples> <command:example> <maml:title>---------- EXAMPLE 1 ----------</maml:title> <maml:introduction> <maml:para>Submits Single Response</maml:para> </maml:introduction> <dev:code>try { 'http://localhost/api' | New-HttpListener -AuthenticationSchemes Basic | Start-HttpListener | Wait-HttpRequest -Count 1 | ForEach-Object { $request = $_ | Receive-HttpRequest | ConvertFrom-Json @{Message="Hello $($request.Name)"} | ConvertTo-Json | Submit-HttpResponse -Request $_ } } finally { Get-HttpListener | Stop-HttpListener }</dev:code> <dev:remarks> <maml:para>Call from *another* shell:</maml:para> <maml:para>$cred = Get-Credential -Message "For PowerShell-REST" -UserName "$ENV:COMPUTERNAME\$ENV:USERNAME" Invoke-RestMethod -Method Post -Uri 'http://localhost/api' -Body $(@{Name='test'} | ConvertTo-Json) -ContentType 'application/json' -Authentication Basic -Credential $cred -AllowUnencryptedAuthentication</maml:para> </dev:remarks> </command:example> <command:example> <maml:title>---------- EXAMPLE 2 ----------</maml:title> <maml:introduction> <maml:para>Submits Indefinite Responses</maml:para> </maml:introduction> <dev:code>try { 'http://localhost/api' | New-HttpListener -AuthenticationSchemes Basic | Start-HttpListener | Wait-HttpRequest -Infinity | ForEach-Object { $request = $_ | Receive-HttpRequest | ConvertFrom-Json @{Message="Hello $($request.Name)"} | ConvertToJson | Submit-HttpResponse -Request $_ } } finally { Get-HttpListener | Stop-HttpListener }</dev:code> <dev:remarks> <maml:para>Call from *another* shell:</maml:para> <maml:para>$cred = Get-Credential -Message "For PowerShell-REST" -UserName "$ENV:COMPUTERNAME\$ENV:USERNAME" Invoke-RestMethod -Method Post -Uri 'http://localhost/api' -Body $(@{Name='test'} | ConvertTo-Json) -ContentType 'application/json' -Authentication Basic -Credential $cred -AllowUnencryptedAuthentication</maml:para> </dev:remarks> </command:example> <command:example> <maml:title>---------- EXAMPLE 3 ----------</maml:title> <maml:introduction> <maml:para>Denies Single Response</maml:para> </maml:introduction> <dev:code>try { 'http://localhost/api' | New-HttpListener -AuthenticationSchemes Basic | Start-HttpListener | Wait-HttpRequest -Count 1 | ForEach-Object { $request = $_ | Receive-HttpRequest | ConvertFrom-Json Deny-HttpResponse -Request $_ } } finally { Get-HttpListener | Stop-HttpListener }</dev:code> <dev:remarks> <maml:para>Call from *another* shell:</maml:para> <maml:para>$cred = Get-Credential -Message "For PowerShell-REST" -UserName "$ENV:COMPUTERNAME\$ENV:USERNAME" Invoke-RestMethod -Method Post -Uri 'http://localhost/api' -Body $(@{Name='test'} | ConvertTo-Json) -ContentType 'application/json' -Authentication Basic -Credential $cred -AllowUnencryptedAuthentication</maml:para> </dev:remarks> </command:example> </command:examples> </command:command> <!-- Cmdlet: Wait-HttpRequest --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name>Wait-HttpRequest</command:name> <command:verb>Wait</command:verb> <command:noun>HttpRequest</command:noun> <maml:description> <maml:para>Waits for a client request.</maml:para> </maml:description> </command:details> <maml:description> <maml:para>This will block while it waits for a client request</maml:para> </maml:description> <command:syntax> <!-- Parameter set: Infinite --> <command:syntaxItem> <maml:name>Wait-HttpRequest</maml:name> <!-- Parameter: InfiniteRequests --> <command:parameter required="true" globbing="false" pipelineInput="false" position="named" aliases="Infinity"> <maml:name>InfiniteRequests</maml:name> <maml:description> <maml:para>Never stop the listener loop.</maml:para> <maml:para>WARNING: be careful of how you are using this because it results in an infinite blocking loop.</maml:para> </maml:description> <command:parameterValue required="true">SwitchParameter</command:parameterValue> <dev:type> <maml:name>System.Management.Automation.SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>False</dev:defaultValue> </command:parameter> <!-- Parameter: Listener --> <command:parameter required="true" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>Listener</maml:name> <maml:description> <maml:para>Used to listen for client requests.</maml:para> </maml:description> <command:parameterValue required="true">HttpListener</command:parameterValue> <dev:type> <maml:name>System.Net.HttpListener</maml:name> <maml:uri /> </dev:type> </command:parameter> </command:syntaxItem> <!-- Parameter set: Limited --> <command:syntaxItem> <maml:name>Wait-HttpRequest</maml:name> <!-- Parameter: Listener --> <command:parameter required="true" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>Listener</maml:name> <maml:description> <maml:para>Used to listen for client requests.</maml:para> </maml:description> <command:parameterValue required="true">HttpListener</command:parameterValue> <dev:type> <maml:name>System.Net.HttpListener</maml:name> <maml:uri /> </dev:type> </command:parameter> <!-- Parameter: NumberOfRequests --> <command:parameter required="false" globbing="false" pipelineInput="false" position="named" aliases="Count"> <maml:name>NumberOfRequests</maml:name> <maml:description> <maml:para>Number of requests to listen for before exiting the listener loop.</maml:para> </maml:description> <command:parameterValue required="true">long</command:parameterValue> <dev:type> <maml:name>System.Int64</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>1</dev:defaultValue> </command:parameter> </command:syntaxItem> </command:syntax> <command:parameters> <!-- Parameter: Listener --> <command:parameter required="true" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>Listener</maml:name> <maml:description> <maml:para>Used to listen for client requests.</maml:para> </maml:description> <command:parameterValue required="true">HttpListener</command:parameterValue> <dev:type> <maml:name>System.Net.HttpListener</maml:name> <maml:uri /> </dev:type> </command:parameter> <!-- Parameter: NumberOfRequests --> <command:parameter required="false" globbing="false" pipelineInput="false" position="named" aliases="Count"> <maml:name>NumberOfRequests</maml:name> <maml:description> <maml:para>Number of requests to listen for before exiting the listener loop.</maml:para> </maml:description> <command:parameterValue required="true">long</command:parameterValue> <dev:type> <maml:name>System.Int64</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>1</dev:defaultValue> </command:parameter> <command:parameter required="false" globbing="false" pipelineInput="false" position="named" aliases="Count"> <maml:name>Count</maml:name> <maml:description> <maml:para>Number of requests to listen for before exiting the listener loop.</maml:para> <maml:para>This is an alias of the NumberOfRequests parameter.</maml:para> </maml:description> <command:parameterValue required="true">long</command:parameterValue> <dev:type> <maml:name>System.Int64</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>1</dev:defaultValue> </command:parameter> <!-- Parameter: InfiniteRequests --> <command:parameter required="true" globbing="false" pipelineInput="false" position="named" aliases="Infinity"> <maml:name>InfiniteRequests</maml:name> <maml:description> <maml:para>Never stop the listener loop.</maml:para> <maml:para>WARNING: be careful of how you are using this because it results in an infinite blocking loop.</maml:para> </maml:description> <command:parameterValue required="true">SwitchParameter</command:parameterValue> <dev:type> <maml:name>System.Management.Automation.SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>False</dev:defaultValue> </command:parameter> <command:parameter required="true" globbing="false" pipelineInput="false" position="named" aliases="Infinity"> <maml:name>Infinity</maml:name> <maml:description> <maml:para>Never stop the listener loop.</maml:para> <maml:para>WARNING: be careful of how you are using this because it results in an infinite blocking loop.</maml:para> <maml:para>This is an alias of the InfiniteRequests parameter.</maml:para> </maml:description> <command:parameterValue required="true">SwitchParameter</command:parameterValue> <dev:type> <maml:name>System.Management.Automation.SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>False</dev:defaultValue> </command:parameter> </command:parameters> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.Net.HttpListener</maml:name> <maml:uri /> </dev:type> <maml:description> <maml:para>Used to listen for client requests.</maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <!-- OutputType: HttpListenerContext --> <command:returnValue> <dev:type> <maml:name>System.Net.HttpListenerContext</maml:name> <maml:uri /> </dev:type> </command:returnValue> </command:returnValues> <command:examples> <command:example> <maml:title>---------- EXAMPLE 1 ----------</maml:title> <maml:introduction> <maml:para>Submits Single Response</maml:para> </maml:introduction> <dev:code>try { 'http://localhost/api' | New-HttpListener -AuthenticationSchemes Basic | Start-HttpListener | Wait-HttpRequest -Count 1 | ForEach-Object { $request = $_ | Receive-HttpRequest | ConvertFrom-Json @{Message="Hello $($request.Name)"} | ConvertTo-Json | Submit-HttpResponse -Request $_ } } finally { Get-HttpListener | Stop-HttpListener }</dev:code> <dev:remarks> <maml:para>Call from *another* shell:</maml:para> <maml:para>$cred = Get-Credential -Message "For PowerShell-REST" -UserName "$ENV:COMPUTERNAME\$ENV:USERNAME" Invoke-RestMethod -Method Post -Uri 'http://localhost/api' -Body $(@{Name='test'} | ConvertTo-Json) -ContentType 'application/json' -Authentication Basic -Credential $cred -AllowUnencryptedAuthentication</maml:para> </dev:remarks> </command:example> <command:example> <maml:title>---------- EXAMPLE 2 ----------</maml:title> <maml:introduction> <maml:para>Submits Indefinite Responses</maml:para> </maml:introduction> <dev:code>try { 'http://localhost/api' | New-HttpListener -AuthenticationSchemes Basic | Start-HttpListener | Wait-HttpRequest -Infinity | ForEach-Object { $request = $_ | Receive-HttpRequest | ConvertFrom-Json @{Message="Hello $($request.Name)"} | ConvertToJson | Submit-HttpResponse -Request $_ } } finally { Get-HttpListener | Stop-HttpListener }</dev:code> <dev:remarks> <maml:para>Call from *another* shell:</maml:para> <maml:para>$cred = Get-Credential -Message "For PowerShell-REST" -UserName "$ENV:COMPUTERNAME\$ENV:USERNAME" Invoke-RestMethod -Method Post -Uri 'http://localhost/api' -Body $(@{Name='test'} | ConvertTo-Json) -ContentType 'application/json' -Authentication Basic -Credential $cred -AllowUnencryptedAuthentication</maml:para> </dev:remarks> </command:example> <command:example> <maml:title>---------- EXAMPLE 3 ----------</maml:title> <maml:introduction> <maml:para>Denies Single Response</maml:para> </maml:introduction> <dev:code>try { 'http://localhost/api' | New-HttpListener -AuthenticationSchemes Basic | Start-HttpListener | Wait-HttpRequest -Count 1 | ForEach-Object { $request = $_ | Receive-HttpRequest | ConvertFrom-Json Deny-HttpResponse -Request $_ } } finally { Get-HttpListener | Stop-HttpListener }</dev:code> <dev:remarks> <maml:para>Call from *another* shell:</maml:para> <maml:para>$cred = Get-Credential -Message "For PowerShell-REST" -UserName "$ENV:COMPUTERNAME\$ENV:USERNAME" Invoke-RestMethod -Method Post -Uri 'http://localhost/api' -Body $(@{Name='test'} | ConvertTo-Json) -ContentType 'application/json' -Authentication Basic -Credential $cred -AllowUnencryptedAuthentication</maml:para> </dev:remarks> </command:example> </command:examples> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Citation.</maml:linkText> <maml:uri>https://docs.microsoft.com/en-us/dotnet/api/system.net.httplistener.getcontext?view=net-5.0#System_Net_HttpListener_GetContext</maml:uri> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- Cmdlet: Deny-HttpResponse --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name>Deny-HttpResponse</command:name> <command:verb>Deny</command:verb> <command:noun>HttpResponse</command:noun> </command:details> <command:syntax> <!-- Parameter set: __AllParameterSets --> <command:syntaxItem> <maml:name>Deny-HttpResponse</maml:name> <!-- Parameter: Context --> <command:parameter required="true" globbing="false" pipelineInput="false" position="named" aliases="Request"> <maml:name>Context</maml:name> <maml:description> <maml:para>The HttpListenerContext that corresponds to the client request.</maml:para> </maml:description> <command:parameterValue required="true">HttpListenerContext</command:parameterValue> <dev:type> <maml:name>System.Net.HttpListenerContext</maml:name> <maml:uri /> </dev:type> </command:parameter> </command:syntaxItem> </command:syntax> <command:parameters> <!-- Parameter: Context --> <command:parameter required="true" globbing="false" pipelineInput="false" position="named" aliases="Request"> <maml:name>Context</maml:name> <maml:description> <maml:para>The HttpListenerContext that corresponds to the client request.</maml:para> </maml:description> <command:parameterValue required="true">HttpListenerContext</command:parameterValue> <dev:type> <maml:name>System.Net.HttpListenerContext</maml:name> <maml:uri /> </dev:type> </command:parameter> <command:parameter required="true" globbing="false" pipelineInput="false" position="named" aliases="Request"> <maml:name>Request</maml:name> <maml:description> <maml:para>The HttpListenerContext that corresponds to the client request.</maml:para> <maml:para>This is an alias of the Context parameter.</maml:para> </maml:description> <command:parameterValue required="true">HttpListenerContext</command:parameterValue> <dev:type> <maml:name>System.Net.HttpListenerContext</maml:name> <maml:uri /> </dev:type> </command:parameter> </command:parameters> <command:inputTypes /> <command:returnValues /> </command:command> <!-- Cmdlet: Submit-HttpResponse --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name>Submit-HttpResponse</command:name> <command:verb>Submit</command:verb> <command:noun>HttpResponse</command:noun> <maml:description> <maml:para>Sends the response to the client and releases the resources held by this HttpListenerResponse instance.</maml:para> </maml:description> </command:details> <maml:description> <maml:para>This should *only* be called once.</maml:para> </maml:description> <command:syntax> <!-- Parameter set: __AllParameterSets --> <command:syntaxItem> <maml:name>Submit-HttpResponse</maml:name> <!-- Parameter: Context --> <command:parameter required="true" globbing="false" pipelineInput="false" position="named" aliases="Request"> <maml:name>Context</maml:name> <maml:description> <maml:para>The HttpListenerContext that corresponds to the client request.</maml:para> </maml:description> <command:parameterValue required="true">HttpListenerContext</command:parameterValue> <dev:type> <maml:name>System.Net.HttpListenerContext</maml:name> <maml:uri /> </dev:type> </command:parameter> <!-- Parameter: Json --> <command:parameter required="true" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>Json</maml:name> <maml:description> <maml:para>The body for the HttpListenerResponse.</maml:para> <maml:para>This is expected to be piped from the ConvertTo-Json Cmdlet.</maml:para> </maml:description> <command:parameterValue required="true">string</command:parameterValue> <dev:type> <maml:name>System.String</maml:name> <maml:uri /> </dev:type> </command:parameter> </command:syntaxItem> </command:syntax> <command:parameters> <!-- Parameter: Json --> <command:parameter required="true" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>Json</maml:name> <maml:description> <maml:para>The body for the HttpListenerResponse.</maml:para> <maml:para>This is expected to be piped from the ConvertTo-Json Cmdlet.</maml:para> </maml:description> <command:parameterValue required="true">string</command:parameterValue> <dev:type> <maml:name>System.String</maml:name> <maml:uri /> </dev:type> </command:parameter> <!-- Parameter: Context --> <command:parameter required="true" globbing="false" pipelineInput="false" position="named" aliases="Request"> <maml:name>Context</maml:name> <maml:description> <maml:para>The HttpListenerContext that corresponds to the client request.</maml:para> </maml:description> <command:parameterValue required="true">HttpListenerContext</command:parameterValue> <dev:type> <maml:name>System.Net.HttpListenerContext</maml:name> <maml:uri /> </dev:type> </command:parameter> <command:parameter required="true" globbing="false" pipelineInput="false" position="named" aliases="Request"> <maml:name>Request</maml:name> <maml:description> <maml:para>The HttpListenerContext that corresponds to the client request.</maml:para> <maml:para>This is an alias of the Context parameter.</maml:para> </maml:description> <command:parameterValue required="true">HttpListenerContext</command:parameterValue> <dev:type> <maml:name>System.Net.HttpListenerContext</maml:name> <maml:uri /> </dev:type> </command:parameter> </command:parameters> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.String</maml:name> <maml:uri /> </dev:type> <maml:description> <maml:para>The body for the HttpListenerResponse.</maml:para> <maml:para>This is expected to be piped from the ConvertTo-Json Cmdlet.</maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues /> <command:examples> <command:example> <maml:title>---------- EXAMPLE 1 ----------</maml:title> <maml:introduction> <maml:para>Submits Single Response</maml:para> </maml:introduction> <dev:code>try { 'http://localhost/api' | New-HttpListener -AuthenticationSchemes Basic | Start-HttpListener | Wait-HttpRequest -Count 1 | ForEach-Object { $request = $_ | Receive-HttpRequest | ConvertFrom-Json @{Message="Hello $($request.Name)"} | ConvertTo-Json | Submit-HttpResponse -Request $_ } } finally { Get-HttpListener | Stop-HttpListener }</dev:code> <dev:remarks> <maml:para>Call from *another* shell:</maml:para> <maml:para>$cred = Get-Credential -Message "For PowerShell-REST" -UserName "$ENV:COMPUTERNAME\$ENV:USERNAME" Invoke-RestMethod -Method Post -Uri 'http://localhost/api' -Body $(@{Name='test'} | ConvertTo-Json) -ContentType 'application/json' -Authentication Basic -Credential $cred -AllowUnencryptedAuthentication</maml:para> </dev:remarks> </command:example> <command:example> <maml:title>---------- EXAMPLE 2 ----------</maml:title> <maml:introduction> <maml:para>Submits Indefinite Responses</maml:para> </maml:introduction> <dev:code>try { 'http://localhost/api' | New-HttpListener -AuthenticationSchemes Basic | Start-HttpListener | Wait-HttpRequest -Infinity | ForEach-Object { $request = $_ | Receive-HttpRequest | ConvertFrom-Json @{Message="Hello $($request.Name)"} | ConvertToJson | Submit-HttpResponse -Request $_ } } finally { Get-HttpListener | Stop-HttpListener }</dev:code> <dev:remarks> <maml:para>Call from *another* shell:</maml:para> <maml:para>$cred = Get-Credential -Message "For PowerShell-REST" -UserName "$ENV:COMPUTERNAME\$ENV:USERNAME" Invoke-RestMethod -Method Post -Uri 'http://localhost/api' -Body $(@{Name='test'} | ConvertTo-Json) -ContentType 'application/json' -Authentication Basic -Credential $cred -AllowUnencryptedAuthentication</maml:para> </dev:remarks> </command:example> </command:examples> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Citation.</maml:linkText> <maml:uri>https://docs.microsoft.com/en-us/dotnet/api/system.net.httplistenerresponse.close?view=net-5.0#System_Net_HttpListenerResponse_Close</maml:uri> </maml:navigationLink> </maml:relatedLinks> </command:command> </helpItems> |