PoshCode Archive  Artifact [eb10a4ccd9]

Artifact eb10a4ccd97ef889174bfac931b563130790d135b4a24ec90c3b0ad965234d0a:

  • File Get-HttpResponseUri.ps1 — part of check-in [34ad8291d7] at 2018-06-10 13:00:27 on branch trunk — Fetch the HEAD for a url and return the ResponseUri. Good for service-independent short-url lengthening ;) (user: unknown size: 1041)

# encoding: ascii
# api: powershell
# title: Get-HttpResponseUri
# description: Fetch the HEAD for a url and return the ResponseUri. Good for service-independent short-url lengthening ;)
# version: 0.1
# type: function
# license: CC0
# function: Get-HttpResponseUri
# x-poshcode-id: 1722
# x-archived: 2010-03-31T09:37:19
#
#
function Get-HttpResponseUri {
#.Synopsis
#   Fetch the HEAD for a url and return the ResponseUri.
#.Description
#   Does a HEAD request for a URL, and returns the ResponseUri. This is useful for resolving (in a service-independent way) shortened urls.
#.Parameter ShortUrl
#   A (possibly) shortened URL to be resolved to its redirect location.
   PARAM(
      [Parameter(Position=0,Mandatory=$true,ValueFromPipeline=$true)]
      [Alias("Uri","Url")]
      [string]$ShortUrl
   )
   $req = [System.Net.HttpWebRequest]::Create($ShortUrl)
   $req.Method = "HEAD"
   $response = $req.GetResponse()
   Write-Output $response.ResponseUri
   $response.Close() # clean up like a good boy
}