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

wulibinbrain 2004-07-23 05:15:31
using classes in System.Net, see

Retrieving HTTP content in .NET
http://www.west-wind.com/presentations/dotnetWebRequest/dotnetWebRequest.htm


string strId = UserId_TextBox.Text;
string strName = Name_TextBox.Text;

ASCIIEncoding encoding=new ASCIIEncoding();
string postData="userid="+strId;
postData += ("&username="+strName);
byte[] data = encoding.GetBytes(postData);

// Prepare web request...
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("http://localhost/MyIdentity/Default.aspx?x=2&y=2");
myRequest.Method = "POST";
myRequest.ContentType="application/x-www-form-urlencoded";
myRequest.ContentLength = data.Length;
Stream newStream=myRequest.GetRequestStream();

// Send the data.
newStream.Write(data,0,data.Length);++++问点1??
newStream.Close();

HttpWebResponse res = (HttpWebResponse) myRequest.GetResponse();


Encoding enc = System.Text.Encoding.GetEncoding("GB2312");


StreamReader sr = new StreamReader(res.GetResponseStream(),enc);


string sHtml = sr.ReadToEnd();


sr.Close();

res.Close();

问点1:newStream.Write(data,0,data.Length);此处是否该为:newStream.Read(data,0,data.Length);

问点2:“myRequest”在什么地方读取的“data”?

问点3:我写的一个给短信网关发送信息的功能为什么运行一次总收到两条短信?代码如下:(大概是这些)
WebRequest re = (HttpWebRequest)WebRequest.Create("http://url?name=strName&pwd=strPwd&message=string&.......");
webResponse rp = (HttpWebResponse)re.GetResponse();
...全文
233 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
wulibinbrain 2004-07-26
  • 打赏
  • 举报
回复
多谢 saucer 的指点!
saucer 2004-07-26
  • 打赏
  • 举报
回复
chain the stream, for example

tClient.Connect("202.99.114.235",8020);
NetworkStream stream = tClient.GetStream();
StreamWriter sw = new StreamWriter(stream, System.Text.Encoding.ASCII);
string strLongin = "Login Name=xxx&Pwd=xxx&Type=x";
sw.Write( strLongin);
....;
wulibinbrain 2004-07-26
  • 打赏
  • 举报
回复
请问“saucer(思归/MVP) ”
我现在用Tcp的方式发送短信,但遇到一个问题:在C#中用System.Net.Sockets.TcpClient创建实例:
TcpClient tClient = new TcpClient();
try
{
tClient.Connect("202.99.114.235",8020);
NetworkStream stream = tClient.GetStream();
string strLongin = "Login Name=xxx&Pwd=xxx&Type=x";
byte[] data = System.Text.Encoding.ASCII.GetBytes(strLongin);
stream.Write(data,0,data.Length);
=====================================================================
在C#中stream.Write()方法的参数中只支持byte[],如何象Delphi中的TcpClient.WriteLn()方法直接可以发送string,在C#中有否与之相当的方法?

einsteincao 2004-07-26
  • 打赏
  • 举报
回复
Saucer is back now :)
  • 打赏
  • 举报
回复
好久没看到思归了哦,顶下
saucer 2004-07-26
  • 打赏
  • 举报
回复
在VS.NET里调试你的编码,我的感觉是你的编码执行了2次

如果是事件函数的话,有可能被绑定了2次
wulibinbrain 2004-07-26
  • 打赏
  • 举报
回复
可以用中文表述详细些吗?
saucer 2004-07-26
  • 打赏
  • 举报
回复
what I meant is to try to debug your code to see if your code is executed twice
wulibinbrain 2004-07-26
  • 打赏
  • 举报
回复
网关没问题的,我直接把请求串加到ie上访问收到一次信息。
可以写一下发送的代码吗?如何做到“add a break point”?
saucer 2004-07-26
  • 打赏
  • 举报
回复
>>>又请求了一次呢?

shouldn't, 只请求一次, try to add a break point in your code, I would think it is executed twice, or something is wrong with your 网关
wulibinbrain 2004-07-26
  • 打赏
  • 举报
回复
>>>make sure the above code is not executed twice

这一点也是我困惑的?
我想问“WebRequest re = (HttpWebRequest)WebRequest.Create("http://url?name=strName&pwd=strPwd&message=string&.......");”这一步是在创建HttpWebRequest;发送是在这一步:“webResponse rp = (HttpWebResponse)re.GetResponse”是不是发送后因为网络响应慢,他没有即时接到响应自己又请求了一次呢?
如果是如何做到等待响应,而只请求一次呢?
saucer 2004-07-25
  • 打赏
  • 举报
回复
>>>为什么运行一次总收到两条短信?

make sure the above code is not executed twice
wulibinbrain 2004-07-24
  • 打赏
  • 举报
回复
问点1、2我已明白!是理解错误了!
还是请问问点3???

62,072

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧