Добавь в этот код возможность использовать прокси: param ( [Parameter(Mandatory=$true)]…
- User
Добавь в этот код возможность использовать прокси: param ( [Parameter(Mandatory=UrlListFilePath )
if (-not $UrlListFilePath) { Write-Host "Path to the file is not provided." exit 1 }
if (-not (Test-Path -Path UrlListFilePath)) { Write-Host "File not found: UrlListFilePath" exit 1 }
function Fetch-Url { param ( [string]$Url )
try { $response = Invoke-WebRequest -Uri $Url -TimeoutSec 10 Write-Host "URL: $Url -> Status code: $($response.StatusCode)" } catch { Write-Host "URL: $Url -> Failed to fetch. Error: $($_.Exception.Message)" }}
while (true) { Get-Content -Path UrlListFilePath | ForEach-Object { Fetch-Url -Url $_ } }
- Assistant
Для добавления возможности использовать прокси, сначала нужно расширить список параметров скрипта для включения данных прокси-сервера. После этого в функцию
Fetch-Urlвключите использование прокси при выполнении запроса. Вот как можно это сделать:param ( [Parameter(Mandatory=$true)] [string]$UrlListFilePath, [string]$ProxyAddress, [string]$ProxyUsername, [string]$ProxyPassword ) if (-not $UrlListFilePath) { Write-Host "Path to the file is not provided." exit 1 } if (-not (Test-Path -Path $UrlListFilePath)) { Write-Host "File not found: $UrlListFilePath" exit 1 } function Fetch-Url { param ( [string]$Url ) $proxy = $null if ($ProxyAddress) { $proxy = New-Object System.Net.WebProxy($ProxyAddress, $true) if ($ProxyUsername -and $ProxyPassword) { $proxyCredentials = New-Object System.Net.NetworkCredential($ProxyUsername, $ProxyPassword) $proxy.Credentials = $proxyCredentials } } try { $webRequestParams = @{ Uri = $Url TimeoutSec = 10 } if ($proxy) { $webRequestParams.Proxy = $proxy } $response = Invoke-WebRequest @webRequestParams Write-Host "URL: $Url -> Status code: $($response.StatusCode)" } catch { Write-Host "URL: $Url -> Failed to fetch. Error: $($_.Exception.Message)" } } while ($true) { Get-Content -Path $UrlListFilePath | ForEach-Object { Fetch-Url -Url $_ } }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.