http://blog.joycode.com/saucer/

阅读更多
换一批

+++++请教“saucer(思归/MVP) ”?++++++

07-23

using classes in System.Net, seernrnRetrieving HTTP content in .NETrnhttp://www.west-wind.com/presentations/dotnetWebRequest/dotnetWebRequest.htmrnrnrn string strId = UserId_TextBox.Text;rn string strName = Name_TextBox.Text;rnrn ASCIIEncoding encoding=new ASCIIEncoding();rn string postData="userid="+strId;rn postData += ("&username="+strName);rn byte[] data = encoding.GetBytes(postData);rnrn // Prepare web request...rn HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("http://localhost/MyIdentity/Default.aspx?x=2&y=2");rn myRequest.Method = "POST";rn myRequest.ContentType="application/x-www-form-urlencoded";rn myRequest.ContentLength = data.Length;rn Stream newStream=myRequest.GetRequestStream();rnrn // Send the data.rn newStream.Write(data,0,data.Length);++++问点1??rn newStream.Close();rnrn HttpWebResponse res = (HttpWebResponse) myRequest.GetResponse();rnrnrn Encoding enc = System.Text.Encoding.GetEncoding("GB2312");rnrn rn StreamReader sr = new StreamReader(res.GetResponseStream(),enc);rnrnrn string sHtml = sr.ReadToEnd();rnrn rn sr.Close();rnrn res.Close();rnrn问点1:newStream.Write(data,0,data.Length);此处是否该为:newStream.Read(data,0,data.Length);rnrn问点2:“myRequest”在什么地方读取的“data”?rnrn问点3:我写的一个给短信网关发送信息的功能为什么运行一次总收到两条短信?代码如下:(大概是这些)rnWebRequest re = (HttpWebRequest)WebRequest.Create("http://url?name=strName&pwd=strPwd&message=string&.......");rn webResponse rp = (HttpWebResponse)re.GetResponse();

没有更多推荐了,返回首页