我在PowerShell v7中使用此代码,发送包含希腊字符的短信。
$message = "testing greek characters ΓΔΘΞΦΨΩ"
$senderId = "smsto1"
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", "Bearer $apikey")
$headers.Add("Content-Type", "application/json; charset=utf-8")
$body = "{`n`"message`": `"$message`",`n`"to`": `"+357$clientPhone`",`n`"sender_id`": `"$senderId`",`n`"encoding`": `"unicode`"`n}"
$response = Invoke-RestMethod 'https://api.sms.to/sms/send' -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json
问题是消息到达时每个希腊字符都显示为问号。这样的:
testing greek characters ???????
我尝试改变$body变量的编码选项为UTF-8, ISO 8859-7和unicode,但我仍然有同样的问题。
我该如何解决这个问题?
我不知道为什么,但是使用GET代替POST工作,没有定义任何编码选项。
$message = "testing greek characters ΓΔΘΞΦΨΩ"
$senderId = "smsto1"
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", "Bearer $apikey")
$headers.Add("Content-Type", "application/json")
$response = Invoke-RestMethod "https://api.sms.to/sms/send?api_key=$apikey&to=+357$clientPhone&message=$message&sender_id=$senderId" -Method 'GET' -Headers $headers