From 7c06504281616188cb3a47555d1201b2593339a0 Mon Sep 17 00:00:00 2001 From: "Namhyeon, Go" Date: Thu, 28 Dec 2023 13:44:00 +0900 Subject: [PATCH] Add WelsonJS-WebRequest powershell script --- app/assets/ps1/WelsonJS-WebRequest.md | 45 ++++++++++++++++++++ app/assets/ps1/WelsonJS-WebRequest.ps1 | 59 ++++++++++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 app/assets/ps1/WelsonJS-WebRequest.md create mode 100644 app/assets/ps1/WelsonJS-WebRequest.ps1 diff --git a/app/assets/ps1/WelsonJS-WebRequest.md b/app/assets/ps1/WelsonJS-WebRequest.md new file mode 100644 index 0000000..d64139b --- /dev/null +++ b/app/assets/ps1/WelsonJS-WebRequest.md @@ -0,0 +1,45 @@ +## WelsonJS-WebRequest.ps1 +이 스크립트를 사용하는 몇 가지 예제를 제공합니다. 스크립트에는 여러 옵션이 있으며 이를 활용하여 다양한 HTTP 요청을 수행할 수 있습니다. + +1. **GET 요청:** + ```powershell + .\WelsonJS-WebRequest.ps1 -url "https://welsonjs.catswords.net/todos/1" + ``` + +2. **POST 요청:** + ```powershell + .\WelsonJS-WebRequest.ps1 -url "https://welsonjs.catswords.net/posts" -method "POST" -data '{"title":"foo","body":"bar","userId":1}' -headers @("Content-Type: application/json") + ``` + +3. **GET 요청 및 결과를 파일로 저장:** + ```powershell + .\WelsonJS-WebRequest.ps1 -url "https://welsonjs.catswords.net/todos/1" -outputFile "output.txt" + ``` + +4. **GET 요청 및 SSL 인증서 검증 무시:** + ```powershell + .\WelsonJS-WebRequest.ps1 -url "https://welsonjs.catswords.net/todos/1" -insecure + ``` + +5. **GET 요청 및 HTTP 프록시 사용:** + ```powershell + .\WelsonJS-WebRequest.ps1 -url "https://welsonjs.catswords.net/todos/1" -proxy "http://proxyserver:8080" + ``` + +6. **GET 요청 및 여러 헤더 전달:** + ```powershell + .\WelsonJS-WebRequest.ps1 -url "https://welsonjs.catswords.net/todos/1" -headers @("Authorization: Bearer YourToken", "CustomHeader: CustomValue") + ``` + +7. **GET 요청 및 SOCKS5 프록시 사용:** + ```powershell + .\WelsonJS-WebRequest.ps1 -url "https://welsonjs.catswords.net/todos/1" -proxy "socks5://proxyserver:1080" + ``` + +8. **POST 요청 및 파일에서 데이터 읽기:** + ```powershell + $dataFromFile = Get-Content -Path "data.json" -Raw + .\WelsonJS-WebRequest.ps1 -url "https://welsonjs.catswords.net/posts" -method "POST" -data $dataFromFile -headers @("Content-Type: application/json") + ``` + +이러한 예제를 통해 다양한 HTTP 요청을 스크립트를 사용하여 처리할 수 있습니다. 필요에 따라 옵션을 추가하거나 수정하여 사용하실 수 있습니다. \ No newline at end of file diff --git a/app/assets/ps1/WelsonJS-WebRequest.ps1 b/app/assets/ps1/WelsonJS-WebRequest.ps1 new file mode 100644 index 0000000..ec5fa51 --- /dev/null +++ b/app/assets/ps1/WelsonJS-WebRequest.ps1 @@ -0,0 +1,59 @@ +# WelsonJS-WebRequest.ps1 +# Namhyeon Go +# https://github.com/gnh1201/welsonjs +param( + [string]$url, + [string]$method = "GET", + [string]$data, + [string]$outputFile, + [switch]$insecure, + [string]$proxy, + [string[]]$headers +) + +# Set headers +$headersHashtable = @{} +if ($headers) { + foreach ($header in $headers) { + $headerParts = $header -split ':', 2 + if ($headerParts.Count -eq 2) { + $headersHashtable[$headerParts[0].Trim()] = $headerParts[1].Trim() + } + } +} + +# Set options for Invoke-RestMethod or Invoke-WebRequest +$options = @{ + Uri = $url + Method = $method + Headers = $headersHashtable + OutFile = $outputFile + ContentType = "application/json" +} + +# Add data if present +if ($data) { + $options["Body"] = $data +} + +# Set proxy if provided +if ($proxy) { + $options["Proxy"] = $proxy +} + +# Disable SSL certificate validation if insecure option is specified +if ($insecure) { + [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true} +} + +# Perform the HTTP request +try { + if ($outputFile) { + Invoke-WebRequest @options + } else { + Invoke-RestMethod @options + } +} finally { + # Restore SSL certificate validation callback + [System.Net.ServicePointManager]::ServerCertificateValidationCallback = $null +}