Skip to content

Commit

Permalink
Fix Windows 7 "Referer header" error
Browse files Browse the repository at this point in the history
* Closes #44
* Also fix incorrect build number for Windows 11 22H2
  • Loading branch information
pbatard committed Sep 21, 2022
1 parent ce7cb58 commit 9beb231
Showing 1 changed file with 38 additions and 29 deletions.
67 changes: 38 additions & 29 deletions Fido.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Fido v1.32 - Feature ISO Downloader, for retail Windows images and UEFI Shell
# Fido v1.33 - Feature ISO Downloader, for retail Windows images and UEFI Shell
# Copyright © 2019-2022 Pete Batard <pete@akeo.ie>
# Command line support: Copyright © 2021 flx5
# ConvertTo-ImageSource: Copyright © 2016 Chris Carter
Expand Down Expand Up @@ -98,7 +98,7 @@ $WindowsVersions = @(
@(
@("Windows 11", "windows11"),
@(
"22H2 (Build 22621.521 - 2022.09)",
"22H2 (Build 22621.382 - 2022.09)",
@("Windows 11 Home/Pro/Edu", 2360),
@("Windows 11 Home China ", ($zh + 2361))
),
Expand Down Expand Up @@ -800,7 +800,16 @@ function Get-Windows-Download-Links([int]$SelectedVersion, [int]$SelectedRelease
$Is64 = [Environment]::Is64BitOperatingSystem
# Must add a referer for POST requests, else Microsoft's servers will deny them
$ref = "https://www.microsoft.com/software-download/windows11"
$r = Invoke-WebRequest -Method Post -Headers @{"Referer" = $ref} -UseBasicParsing -UserAgent $UserAgent -WebSession $Session $url
$wr = [System.Net.WebRequest]::Create($url)
# Windows 7 PowerShell doesn't support 'Invoke-WebRequest -Headers @{"Referer" = $ref}'
# (produces "The 'Referer' header must be modified using the appropriate property or method")
# so we use StreamReader() with GetResponseStream() and do this whole gymkhana instead...
$wr.Method = "POST"
$wr.Referer = $ref
$wr.UserAgent = $UserAgent
$wr.ContentLength = 0
$sr = New-Object System.IO.StreamReader($wr.GetResponse().GetResponseStream())
$r = $sr.ReadToEnd()
if ($r -match "errorModalMessage") {
Throw-Error -Req $r -Alt "Could not retrieve architectures from server"
}
Expand Down Expand Up @@ -1163,8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Ve9nQbbwqf+q4nHnkBo2GC0Yy/DxnX4guloxGcw/9DVwxzzC7ItJEG0qmAY0Pl
# bdDVLyldAwZYcY43LriCS80x5xLZQjkpPSQurs3uTcGbwkqno20XZdRMSvUYdI0K
# how//ZKXn9XcQGcvaCIGCzttS433m3khkILUiVvZNOqGERX6BqNjX5OX4QscK1uR
# kRKEPdL9WMIv3MX902bnnC8OqeuHcKcjdIuokzGfDYoGJe8aGOWTsScivdft+5Go
# C1W4KLv7+jEF0n05S0Sd/ebBFYM4Zq2EQVpj1KeLyrPHonZYwZGzbXpwRC3W
# SIG # End signature block

1 comment on commit 9beb231

@AgentSam
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for this Windows 7 compatibility fix!

And forgive me for being so "entrenched" that I still need Windows 7 on some of my systems.

Please sign in to comment.