0
我有一個Windows應用程序,在C #
寫,有一個網絡監聽和PHP
頁從mysql
數據庫中獲取一個字符串,並通過套接字窗口發送字符串應用程序使用此代碼:獲取UTF8字符串
$remote_ip='192.168.5.133';//this is the ip of computer that run windows app
ini_set('display_errors',off);
$sh=fsockopen($remote_ip,6000,$en,$en,1);
ini_set('display_errors',on);
fputs($sh,$Text_To_Send_Windows_Application);
$test_keycard=fread($sh,2);
fclose($sh);
當我收到在Windows應用程序中的字符串,有一樣的東西:
¨ÛستÙUU©Ø§Ø³ÙÙدÙزارÙØ ³ÛØμدÙÙUUOÙ¾Ùج
我嘗試將此代碼轉換爲UTF-8格式,在C#中這絲毫代碼
string plainText = UTF8Encoding.UTF8.GetString(UTF8encodes);
但它不會返回原始的字符串。
任何人都可以告訴我如何從我的PHP
頁面發送原始字符串?
你有一個網頁無效的html字符(請參閱:https://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references)因此,使用網絡庫中的WebUtility:System.Net.WebUtility.HtmlDecode()或System.Net.WebUtility.HtmlEncode() – jdweng
WebU tility.HtmlDecode返回確切的輸入字符串...關於無效的html字符,我將它設置爲utf8 ...你的意思是它必須是別的東西? –
是的。 utf8只是將ASCII字符0-255轉換爲沒有轉換的字節數組。 WebUtility會在我提供的網頁鏈接上顯示轉換。 – jdweng