[英]Set encoding between PHP soap server and c# soap client
我有一台PHP SOAP服務器(將nuSOAP與wsdl一起使用)發送html頁面的內容。 當然,可以使用不同的編碼方式來編碼HTML,這就是問題出現的時候了。 如果使用PHP SOAP客戶端,則可以發送如下編碼:
$clienteSOAP = new SoapClient ("http://test.mine.com/wsdl/filemanager?wsdl",
array ('encoding' => 'ISO-8859-15'));
$clienteSOAP->__soapCall ("Test.uploadHTML",
array (file_get_contents ('/home/КОЛЛЕКЦИЯ_РОДНИК_ПРЕМИУМ.html')));
如果我輸入正確的編碼,到目前為止,它從未失敗過。 但是,當我使用C#客戶端時,如何將編碼放入Web服務請求中? 在C#中,代碼為:
System.IO.StreamReader html = new System.IO.StreamReader (
"C:\\Documents and Settings\\КОЛЛЕКЦИЯ_РОДНИК_ПРЕМИУМ.html"
,System.Text.Encoding.GetEncoding("iso-8859-15"));
string contenido = html.ReadToEnd();
html.Close();
Test.FileManager upload = new Test.FileManager();
string resultado = upload.TestUploadHTML (contenido);
Test.FileManager是wsdl的Web參考,當我看到“上傳html”時,某些字符不正確。
提前致謝。
nusoap內部使用php函數xml_parser_create,該函數僅支持: ISO-8859-1,UTF-8和US-ASCII 。 因此,該庫無法與其他編碼配合使用。 偉大的PacHecoPe ...
更新:就我而言,最好的選擇是以原始編碼讀取存檔並將其轉換為utf-8:
System.IO.StreamReader html = new System.IO.StreamReader (
"C:\\Documents and Settings\\КОЛЛЕКЦИЯ_РОДНИК_ПРЕМИУМ.html"
,System.Text.Encoding.GetEncoding("iso-8859-15"));
string contenido = html.ReadToEnd();
html.Close();
System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
byte[] bytes = System.Text.Encoding.UTF8.GetBytes (contenido);
string contenidoUTF8 = encoder.GetString(bytes);
upload.RequestEncoding = System.Text.Encoding.GetEncoding("UTF-8");
Test.FileManager upload = new Test.FileManager();
string resultado = upload.TestUploadHTML (contenidoUTF8);
UPDATE2:使用big5之類的UTF-8不支持的編碼,上面的代碼不能很好地工作。 因此,最好不要將其轉換為UTF-8並在wsdl中將html的內容(如base64Binary)設置為參數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.