Discussion:
關於 Uri 及 WebRequest
(时间太久无法回复)
JimmyHsiao
2006-04-10 03:37:02 UTC
Permalink
ASP

send.asp 內容

<%Response.write Request("msg")%>


2003 C# 內容

string smsURL = "http://127.0.0.1", smsURLVar = "/sms/send.asp?msg=主機發生異常";

System.Uri baseuri = new Uri(smsURL, true);
System.Uri uri = new Uri(baseuri, smsURLVar, true);

WebRequest req = HttpWebRequest.Create(uri);
req.Method = "GET";
req.ContentType = "application/x-www-form-urlencoded";

WebResponse rep = req.GetResponse();
Stream ReceiveStream = rep.GetResponseStream();
Encoding encode = System.Text.Encoding.Default;
StreamReader readStream = new StreamReader( ReceiveStream, encode );
string ret_code = readStream.ReadLine();
MessageBox.Show(ret_code);

結果 ret_code 會出現 ??????, 請問一下那裡沒有做對, 感謝
璉璉
2006-04-10 05:23:39 UTC
Permalink
œÐ¥ýžÕ­^ŒÆ¡A­^ŒÆšS°ÝÃDªºžÜ¡A«Øij§A§â€€€å°µ UrlEncode œsœX¡C
©ó news:23D35535-D2B4-42F2-91F7-B4C803393E04%40microsoft.com µoªí
ASP
send.asp €º®e
<%Response.write Request("msg")%>
2003 C# €º®e
string smsURL = "http://127.0.0.1", smsURLVar = "/sms/send.asp?msg=¥DŸ÷µo¥Í²§±`";
System.Uri baseuri = new Uri(smsURL, true);
System.Uri uri = new Uri(baseuri, smsURLVar, true);
WebRequest req = HttpWebRequest.Create(uri);
req.Method = "GET";
req.ContentType = "application/x-www-form-urlencoded";
WebResponse rep = req.GetResponse();
Stream ReceiveStream = rep.GetResponseStream();
Encoding encode = System.Text.Encoding.Default;
StreamReader readStream = new StreamReader( ReceiveStream, encode );
string ret_code = readStream.ReadLine();
MessageBox.Show(ret_code);
--
€ô®ü¬ì§Þšt²Î¬ãµoÅçÃÒ€u§@«Ç ASP.NET Web News Reader 0.2.0 UTF-8 Beta
·s»Džs²Õ RSSºô»xµo¥¬ŽúžÕ€€ http://tlcheng.no-ip.com/News/rss2.aspx
ºô¯žŠa¹Ï http://tlcheng.no-ip.com/wwwmap.htm
¬y°ìšŸ¬x/°Ï°ì€ôžê·œ/®}ª@ºô/ªŽºÀ¹Ï/»y­µ³q°T €å³¹»Pµ{Š¡
Basic/Fortran/Windows API/.Net/»²§U»¡©úÀÉ ­ì©lœX¡B€å³¹»P°Qœ×
--
ASPNET News http://tlcheng.no-ip.com/News/ | http://tlcheng.twbbs.org/News/
RSS 2.0 http://tlcheng.no-ip.com/News/rss2.aspx?Action=List&Newsgroup=microsoft.public.tw.dotnet.framework.aspnet
JimmyHsiao
2006-04-10 06:06:01 UTC
Permalink
我使用
UrlEncode 出來的是亂碼, %e4%b8%bb%e6%a9%9f%e7%99%bc%e7%94%9f%e7%95%b0%e5%b8%b8
UrlEncodeUnicode 出來的是 OK 的 %u4e3b%u6a5f%u767c%u751f%u7570%u5e38

HttpWebRequest.Create 的編碼是什麼, 因為到現在都搞不定

"璉璉" 來函:
請先試英數,英數沒問題的話,建議你把中文做 UrlEncode 編碼。
於 news:23D35535-D2B4-42F2-91F7-B4C803393E04%40microsoft.com 發表
ASP
send.asp 內容
<%Response.write Request("msg")%>
2003 C# 內容
string smsURL = "http://127.0.0.1", smsURLVar = "/sms/send.asp?msg=主機發生異常";
System.Uri baseuri = new Uri(smsURL, true);
System.Uri uri = new Uri(baseuri, smsURLVar, true);
WebRequest req = HttpWebRequest.Create(uri);
req.Method = "GET";
req.ContentType = "application/x-www-form-urlencoded";
WebResponse rep = req.GetResponse();
Stream ReceiveStream = rep.GetResponseStream();
Encoding encode = System.Text.Encoding.Default;
StreamReader readStream = new StreamReader( ReceiveStream, encode );
string ret_code = readStream.ReadLine();
MessageBox.Show(ret_code);
結果 ret_code 會出現 ??????, 請問一下那裡沒有做對, 感謝
--
水海科技系統研發驗證工作室 ASP.NET Web News Reader 0.2.0 UTF-8 Beta
新聞群組 RSS網誌發布測試中 http://tlcheng.no-ip.com/News/rss2.aspx
網站地圖 http://tlcheng.no-ip.com/wwwmap.htm
流域防洪/區域水資源/徐昇網/玫瑰圖/語音通訊 文章與程式
Basic/Fortran/Windows API/.Net/輔助說明檔 原始碼、文章與討論
--
ASPNET News http://tlcheng.no-ip.com/News/ | http://tlcheng.twbbs.org/News/
RSS 2.0 http://tlcheng.no-ip.com/News/rss2.aspx?Action=List&Newsgroup=microsoft.public.tw.dotnet.framework.aspnet
JimmyHsiao
2006-04-10 05:33:01 UTC
Permalink
再說明一下

我如果直接貼在 IE 上 http://127.0.0.1/sms/send.asp?msg=主機發生異常, 這樣子是OK的

我想要再問一下, IE 的編碼是這樣子的

"JimmyHsiao" 來函:
Post by JimmyHsiao
ASP
send.asp 內容
<%Response.write Request("msg")%>
2003 C# 內容
string smsURL = "http://127.0.0.1", smsURLVar = "/sms/send.asp?msg=主機發生異常";
System.Uri baseuri = new Uri(smsURL, true);
System.Uri uri = new Uri(baseuri, smsURLVar, true);
WebRequest req = HttpWebRequest.Create(uri);
req.Method = "GET";
req.ContentType = "application/x-www-form-urlencoded";
WebResponse rep = req.GetResponse();
Stream ReceiveStream = rep.GetResponseStream();
Encoding encode = System.Text.Encoding.Default;
StreamReader readStream = new StreamReader( ReceiveStream, encode );
string ret_code = readStream.ReadLine();
MessageBox.Show(ret_code);
結果 ret_code 會出現 ??????, 請問一下那裡沒有做對, 感謝
Loading...