C HttpRequest 中文編碼問題

2021-06-06 23:38:22 字數 1008 閱讀 7977

工作中的專案要用到別家的網路簡訊平台,工作中遇到中文編碼的問題,特總結以備忘。

get方法:

public

string

dowebrequest(

string

url)

catch

(webexception

e)            

catch

(exception

e)            

finally

webresponse.close();

//關閉web響應流

}            }

return

responsestr;

}

注意:url中的中文,要先用

urlencode("內容",編碼) 用伺服器接收的編碼,編碼一下。

post方法:

private

string dowebrequestbypost(string url, string param)

trycatch (exception)

finally

webresponse.close();//關閉web響應流}}

return responsestr;

}

encoding為伺服器接收的編碼,例如:encoding.getencoding("gbk")等

param post請求的引數 param1=123¶m2=中國¶m3=abc 這樣的格式,中文部分不用使用編碼,方法內轉成byte時

會進行編碼。

FileReader讀取中文txt檔案編碼丟失問題

有乙個utf 8編碼的文字檔案,用filereader讀取到乙個字串,然後轉換字符集 str new string str.getbytes utf 8 結果大部分中文顯示正常,但最後仍有部分漢字顯示為問號!public static listgetlines string filename br....

windows下gvim 寫html 中文編碼

vim 下配置檔案vimrc 有三個與編碼有關的引數 encoding fileencoding,fileencodings encoding 的作用是在fileencoding為空的情況下,新建檔案的預設編碼,在windows 環境下預設的cp936,和終端環境編碼相同,修改容易造成終端環境亂碼 ...

pymysql插入和查詢mysql中文編碼設定

centos7 mysql5.7.22 pythen3.6 pymysql 在 mysql 標籤下加上一行 default character set utf8 在 mysql.server 標籤下加上一行 default character set utf8 在 mysqld safe 標籤下加上...