Skip to content

Invoke-WebRequest: Head request failing after update to v7.3.0 #18531

Closed

Description

Prerequisites

Steps to reproduce

Invoke-WebRequest -Uri 'https://www.foxit.com/downloads/latest.html?product=Foxit-Reader&platform=Windows&version=&package_type=exe&language=German' -Method Head

Expected behavior

Invoke-WebRequest succeeds without issues.

I cannot reproduce this behavior with v7.2.7.

Actual behavior

Invoke-WebRequest fails. The provided URI is claimed to be invalid, since the hostname is not parsed correctly.

Error details

Exception             : 
    Type       : System.UriFormatException
    TargetSite : 
        Name          : CreateThis
        DeclaringType : uri
        MemberType    : Method
        Module        : System.Private.Uri.dll
    Message    : Invalid URI: The hostname could not be parsed.
    Source     : System.Private.Uri
    HResult    : -2146233033
    StackTrace : 
   at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind, UriCreationOptions& creationOptions)
   at System.Uri.CreateUri(Uri baseUri, String relativeUri, Boolean dontEscape)
   at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ParseLinkHeader(HttpResponseMessage response, Uri requestUri)
   at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord()
   at System.Management.Automation.CommandProcessor.ProcessRecord()
CategoryInfo          : NotSpecified: (:) [Invoke-WebRequest], UriFormatException
FullyQualifiedErrorId : System.UriFormatException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
InvocationInfo        : 
    MyCommand        : Invoke-WebRequest
    ScriptLineNumber : 1
    OffsetInLine     : 1
    HistoryId        : 5
    Line             : Invoke-WebRequest -Uri 'https://www.foxit.com/downloads/latest.html?product=Foxit-Reader&platform=Windows&version=&package_type=exe&language=German' -Method Head
    PositionMessage  : At line:1 char:1
                       + Invoke-WebRequest -Uri 'https://www.foxit.com/downloads/latest.html?p …
                       + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    InvocationName   : Invoke-WebRequest
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1

Environment data

Name                           Value
----                           -----
PSVersion                      7.3.0
PSEdition                      Core
GitCommitId                    7.3.0
OS                             Microsoft Windows 10.0.22621
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

Activity

  1. added
    Needs-Triage
    on Nov 11, 2022
  2. SteveL-MSFT commented on Nov 14, 2022

    @SteveL-MSFT
    Member

    This doesn't repro for me on Windows with 7.3.0:

    PowerShell 7.3.0
    C:\Users\slee
    PS> Invoke-WebRequest -Uri 'https://www.foxit.com/downloads/latest.html?product=Foxit-Reader&platform=Windows&version=&package_type=exe&language=German' -Method Head
    
    StatusCode        : 200
    StatusDescription : OK
    Content           : {}
    RawContent        : HTTP/1.1 200 OK
                        Date: Mon, 14 Nov 2022 21:07:11 GMT
                        Server: Apache/2.4.10
                        Server: (Debian)
                        ETag: "bd1be58-5ec5f4890509a"
                        Accept-Ranges: bytes
                        Last-Modified: Tue, 01 Nov 2022 02:14:27 GMT
                        Conten…
    Headers           : {[Date, System.String[]], [Server, System.String[]], [ETag, System.String[]], [Accept-Ranges, System.String[]]…}
    RawContentLength  : 0
    RelationLink      : {}

    Does this repro consistently for you?

  3. brogers5 commented on Nov 14, 2022

    @brogers5
    Author

    I can only consistently reproduce this on one of my devices: a self-assembled desktop running Windows 11 22H2.

    I've attempted reproduction from a Dell XPS 13 9310 2-in-1 (personal laptop) running Windows 11 22H2, as well as an HP ZBook Studio G5 (work laptop) running Windows 10 Enterprise 20H2. The request succeeded on both devices without issues.

    On the failing device, the call succeeds in Windows PowerShell, but I'm seeing a different response which may be relevant:

    StatusCode        : 200
    StatusDescription : OK
    Content           : {}
    RawContent        : HTTP/1.1 200 OK
                        Link: <https://*.foxitsoftware.com/product/manifest.txt>; rel=prefetch
                        Accept-Ranges: bytes
                        Content-Length: 198295128
                        Content-Type: application/x-msdos-program
                        Date: Mon, 14 Nov 2...
    Headers           : {[Link, <https://*.foxitsoftware.com/product/manifest.txt>; rel=prefetch], [Accept-Ranges, bytes], [Content-Length, 198295128],
                        [Content-Type, application/x-msdos-program]...}
    RawContentLength  : 0

    Based on the stack trace, I'm guessing we're trying to parse the Link header's URI, which fails:

    PS C:\Users\brian> [System.Uri]::new('https://*.foxitsoftware.com/product/manifest.txt')
    MethodInvocationException: Exception calling ".ctor" with "1" argument(s): "Invalid URI: The hostname could not be parsed."
  4. adityapatwardhan commented on Nov 14, 2022

    @adityapatwardhan
    Member

    It seems that the regression was introduced by this change: #15973
    Maybe Steven (@sliekens) can help here?

  5. sliekens commented on Nov 15, 2022

    @sliekens
    Contributor

    Aditya Patwardhan (@adityapatwardhan) Brian Rogers (@brogers5)

    I can see that the server is using unquoted rel types. (rel=prefetch instead of rel="prefetch")

    • PowerShell versions older than 7.3.0 completely ignore Link headers with unquoted reltypes.
      • (Technically, the regex patten didn't match)
    • PowerShell 7.3.0 does support them, but now you have a different problem because * is not an allowed character for a hostname.
    • It seems the server is also not consistently returning a Link header.
  6. SteveL-MSFT commented on Nov 21, 2022

    @SteveL-MSFT
    Member

    We should probably update the code so that if there is an exception parsing the links, we just leave the links empty and maybe emit a warning message.

  7. microsoft-github-policy-service commented on Nov 15, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  8. microsoft-github-policy-service commented on Nov 15, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  9. added
    Resolution-No Activity
    on Nov 15, 2023
  10. microsoft-github-policy-service commented on Nov 15, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  11. microsoft-github-policy-service commented on Nov 22, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs-TriageResolution-No ActivityWG-Cmdlets

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions