使用WebRequest時,URL中含有中文的問題

2022-02-06 06:36:11 字數 375 閱讀 5099

如下url:北京,由於中間有中文字元,傳到webrequest中時,得不到正確結果。為了使webrequest操作時,url支援中文,需要對這些中文特殊處理一下:

encoding ed=encoding.getencoding("gb2312");

webrequest req = webrequest.create("" + httputility.urlencode("北京", ed));

webresponse response = req.getresponse();

string content = string.empty;

using (stream st = response.getresponsestream())

搞定!

WebRequest 物件的使用

內容比較簡單,直接看 的注釋即可。待請求的位址 string url 建立 webrequest 物件,webrequest 是抽象類,定義了請求的規定,可以用於各種請求,例如 http,ftp 等等。httpwebrequest 是 webrequest 的派生類,專門用於 http 請求的方式通...

WebRequest使用 呼叫新浪天氣

待請求的位址 string url 建立 webrequest 物件,webrequest 是抽象類,定義了請求的規定,可以用於各種請求,例如 http,ftp 等等。httpwebrequest 是 webrequest 的派生類,專門用於 http 請求的方式通過 method 屬性設定 預設為...

為什麼本地開發時使用CURL請求本地URL會卡死

預設時啟動phpcgi是 d php php cgi.exe b 127.0.0.1 9000 c d phpfind phpa php.ini 先看nginx配置12 3456 789location php nginx中,看php檔案塊fastcig pass的設定值 127.0.0.1 900...