Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions Utils/Data.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function ReadAllData([string]$filepath) {
}

$invalid = $false
if (-not $data -is [array]) {
if (-not ($data -is [array])) {
$invalid = $true
}

Expand Down Expand Up @@ -185,10 +185,10 @@ function SaveTargetData(
name = $name
method = $method
url = $url
headers = [hashtable]$headers
headers = $headers
body = @{
type = $contentType
content = [hashtable]$body
content = $body
}
}

Expand All @@ -210,11 +210,11 @@ function LoadTargetData([string]$target) {
$headers = $null
if ($null -ne $data.headers) {
$headers = New-Object System.Collections.Generic.Dictionary'[String,String]'
$keys = ($data.headers | Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty Name)
for ($j=0; $j -lt $keys.Length; $j++) {
$key = $keys[$j]
$value = $data.headers[$key]
$headers.Add($key, $value)
# Use PSObject.Properties to reliably read PSCustomObject values.
foreach ($prop in $data.headers.PSObject.Properties) {
$key = $prop.Name
$value = $prop.Value
$headers.Add($key, [string]$value)
}
}

Expand All @@ -237,6 +237,8 @@ function LoadTargetData([string]$target) {
}
}

write-host "headers: $headers"
write-host "body: $body"
return @($true, $method, $url, $headers, $contentType, $body)
}

Expand Down
10 changes: 5 additions & 5 deletions Utils/Requester.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function DisableSSL() {
}

function ForceTls12() {
[System.Net.ServicePointManager]::SecurityProtocol = "tls12, tls11"
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
}

function Request(
Expand All @@ -43,15 +43,15 @@ function Request(
if ($null -eq $requestContentType -and
$null -eq $requestHeaders -and
$null -eq $requestBody) {
$response = (Invoke-WebRequest -Method $requestMethod -Uri $requestUrl)
$response = (Invoke-WebRequest -Method $requestMethod -Uri $requestUrl -UseBasicParsing)
} elseif (
$null -eq $requestHeaders -and
$null -eq $requestBody) {
$response = (Invoke-WebRequest -Method $requestMethod -Uri $requestUrl -ContentType $requestContentType)
$response = (Invoke-WebRequest -Method $requestMethod -Uri $requestUrl -ContentType $requestContentType -UseBasicParsing)
} elseif ($null -eq $requestBody) {
$response = (Invoke-WebRequest -Method $requestMethod -Uri $requestUrl -ContentType $requestContentType -Headers $requestHeaders)
$response = (Invoke-WebRequest -Method $requestMethod -Uri $requestUrl -ContentType $requestContentType -Headers $requestHeaders -UseBasicParsing)
} else {
$response = (Invoke-WebRequest -Method $requestMethod -Uri $requestUrl -ContentType $requestContentType -Headers $requestHeaders -Body $requestBody)
$response = (Invoke-WebRequest -Method $requestMethod -Uri $requestUrl -ContentType $requestContentType -Headers $requestHeaders -Body $requestBody -UseBasicParsing)
}

$responseStatusCode = $response.StatusCode
Expand Down
2 changes: 1 addition & 1 deletion Utils/Writer.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function WriteRecord(
$content += "請求身體:`n"

if ($requestBody -is [string]) {
$conetnt += "$requestBody`n"
$content += "$requestBody`n"
}

if ($requestBody -is [System.Collections.Generic.Dictionary[[string],[object]]]) {
Expand Down
8 changes: 4 additions & 4 deletions Windows/MainWindow.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ function onAddButtonClick(
}

$body = $null
if ($reqMethod -eq 'POST' -or $reqMethod -eq 'PUT') {
if ($method -eq 'POST' -or $method -eq 'PUT') {
$bodyValue = GenerateRequestBody
$bodySuccess = $bodyValue[0]
$body = $bodyValue[1]
Expand Down Expand Up @@ -1117,7 +1117,7 @@ function GenerateRequestBody () {
return GenerateRequestOtherBody
}

return ($true, $null)
return @($true, $null)
}

function GenerateRequestJsonBody() {
Expand All @@ -1135,7 +1135,7 @@ function GenerateRequestJsonBody() {

if ($verifyJson) {
try {
ConvertFrom-Json $body
$null = ConvertFrom-Json $body
} catch {
[System.Windows.Forms.MessageBox]::Show(
'請確認請求體 JSON 字串內容格式正確',
Expand Down Expand Up @@ -1164,7 +1164,7 @@ function GenerateRequestXmlBody() {

if ($verifyXml) {
try {
[xml]$body
$null = [xml]$body
} catch {
[System.Windows.Forms.MessageBox]::Show(
'請確認請求體 XML 字串內容格式正確',
Expand Down
18 changes: 12 additions & 6 deletions Windows/SettingWindow.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
[System.Windows.Forms.RadioButton]$script:disableSSLRadioButtonEnable = $null
[System.Windows.Forms.RadioButton]$script:disableSSLRadioButtonDisable = $null

[System.Windows.Forms.RadioButton]$script:forceTls12RadioButtonEnable = $null
[System.Windows.Forms.RadioButton]$script:forceTls12RadioButtonDisable = $null

[System.Windows.Forms.RadioButton]$script:verifyJsonRadioButtonEnable = $null
[System.Windows.Forms.RadioButton]$script:verifyJsonRadioButtonDisable = $null

Expand Down Expand Up @@ -95,14 +98,14 @@ function InitView() {
$forceTls12RadioButtonEnable = New-Object System.Windows.Forms.RadioButton
$forceTls12RadioButtonEnable.Text = '啟用'
$forceTls12RadioButtonEnable.Font = '微軟正黑體,10pt'
$forceTls12RadioButtonEnable.Checked = GetDisableSSL
$forceTls12RadioButtonEnable.Checked = GetForceTls12
$forceTls12Layout.Controls.Add($forceTls12RadioButtonEnable, 1, 0)

$forceTls12ButtonDisable = New-Object System.Windows.Forms.RadioButton
$forceTls12ButtonDisable.Text = '禁用'
$forceTls12ButtonDisable.Checked = -not (GetDisableSSL)
$forceTls12ButtonDisable.Font = '微軟正黑體,10pt'
$forceTls12Layout.Controls.Add($forceTls12ButtonDisable, 2, 0)
$forceTls12RadioButtonDisable = New-Object System.Windows.Forms.RadioButton
$forceTls12RadioButtonDisable.Text = '禁用'
$forceTls12RadioButtonDisable.Checked = -not (GetForceTls12)
$forceTls12RadioButtonDisable.Font = '微軟正黑體,10pt'
$forceTls12Layout.Controls.Add($forceTls12RadioButtonDisable, 2, 0)

$verifyJsonLayout = New-Object System.Windows.Forms.TableLayoutPanel
$verifyJsonLayout.CellBorderStyle = 'None'
Expand Down Expand Up @@ -244,6 +247,8 @@ function InitView() {
$script:cancelButton = $cancelButton
$script:disableSSLRadioButtonEnable = $disableSSLRadioButtonEnable
$script:disableSSLRadioButtonDisable = $disableSSLRadioButtonDisable
$script:forceTls12RadioButtonEnable = $forceTls12RadioButtonEnable
$script:forceTls12RadioButtonDisable = $forceTls12RadioButtonDisable
$script:verifyJsonRadioButtonEnable = $verifyJsonRadioButtonEnable
$script:verifyJsonRadioButtonDisable = $verifyJsonRadioButtonDisable
$script:verifyXmlRadioButtonEnable = $verifyXmlRadioButtonEnable
Expand All @@ -270,6 +275,7 @@ function OnSaveButtonClick(
[System.EventArgs]$e
) {
SetDisableSSL $script:disableSSLRadioButtonEnable.Checked
SetForceTls12 $script:forceTls12RadioButtonEnable.Checked
SetVerifyJson $script:verifyJsonRadioButtonEnable.Checked
SetVerifyXml $script:verifyXmlRadioButtonEnable.Checked
SetAutoSave $script:autoSaveRadioButtonEnable.Checked
Expand Down