[英]C# Send unicode SMS using UTF8 encoding
我正在使用http api發送短信。 我有以下php代碼發送unicode短信
<?php
$api_key = 'XXXXXX';
$contacts = '97656XXXXX,98012XXXXX';
$from = 'DEMO';
$sms_text = 'Hindi - हिंदी , Chinese - 痴呢色 ,Russian - руссиан';
$encoded_text = utf8_encode($sms_text);
$message = urlencode($encoded_text);
$api_url = "http://www.example.in/app/smsapi/index.php?key=".$api_key."&campaign=1&type=unicode&contacts=".$contacts."&senderid=".$from."&msg=".$message;
//Submit to server
$response = file_get_contents( $api_url);
echo $response;
?>
php代碼正確發送消息。 現在在這里,我想使用c#
發送相同的內容。 我嘗試了以下代碼。
WebClient objClient = new WebClient();
string baseurl = SystemConfiguration.GetSendSMSURL();
byte[] utfByte = Encoding.UTF8.GetBytes(message);
baseurl = string.Format(baseurl, recipientMobileNumber, HttpUtility.UrlEncode(utfByte));
Stream data = objClient.OpenRead(baseurl);
StreamReader reader = new StreamReader(data);
string s = reader.ReadToEnd();
data.Close();
reader.Close();
但是它不能正常工作。 我收到了?????
在Unicode字符的短信中。 基本上我正在嘗試在C#中轉換php代碼。 有人可以告訴我在C#中哪里做錯了嗎?
我想
type=unicode
也包含在C#中的SMS URL中。 (它不在您的代碼示例中。) 如果所有這些都是真的,我建議您嘗試直接在消息上使用HttpUtility.UrlEncode,而不是先將其轉換為byte[]
數組。 string
在C#.NET中已經是unicode。
baseurl = string.Format(baseurl, recipientMobileNumber, HttpUtility.UrlEncode(message));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.