请问一个http post返回值的问题?

chp890310 2011-08-23 03:22:26
winform:
 string strUrl = "http://localhost:1720/WebSite5/Default.aspx";
HttpWebRequest myReq =(HttpWebRequest)WebRequest.Create(strUrl);
myReq.Method = "post";
myReq.ContentType = "application/x-www-form-urlencoded";
myReq.ReadWriteTimeout = 1000;
HttpWebResponse myRes = (HttpWebResponse)myReq.GetResponse();
Stream streamReq = myRes.GetResponseStream();
StreamReader reader = new StreamReader(streamReq, System.Text.Encoding.UTF8);
string s = reader.ReadToEnd();
MessageBox.Show(s);

website:
protected void Page_Load(object sender, EventArgs e)
{
Stream inputStream = HttpContext.Current.Request.InputStream;
StreamReader reader = new StreamReader(inputStream, System.Text.Encoding.UTF8);
string responseContent = reader.ReadToEnd();
Response.ContentType = "text/plain";
Response.Write(responseContent);
}

我让winform向website 发出http post请求,website向winform返回一个字符串,但是我用上面代码essageBox.Show(s)显示的是整个网页?怎么做才可以返回的一个字符串?
...全文
312 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
chp845 2011-08-23
  • 打赏
  • 举报
回复
protected void Page_Load(object sender, EventArgs e)
{
Stream inputStream = HttpContext.Current.Request.InputStream;
StreamReader reader = new StreamReader(inputStream, System.Text.Encoding.UTF8);
string responseContent = reader.ReadToEnd();
Response.ContentType = "text/plain";
Response.Write(responseContent);
Response.End();//加上这句
}
LMAOhuaNL 2011-08-23
  • 打赏
  • 举报
回复
等等

req.open("get", "xxx.aspx");//错咯
应该是
req.open("get", "222.aspx");
LMAOhuaNL 2011-08-23
  • 打赏
  • 举报
回复
哦你的意思的话就用ajax呗
xxx.aspx页面
<script type="text/javascript" language="javascript">
var req=null;
function onSendMessage() {
req = new XMLHttpRequest();
req.open("get", "xxx.aspx");
req.send();
req.onreadystatechange = function () {
if (req.readyState == 4 && req.status == 200) {
var str=req.responseText; //服务器那边返回来的字符串
alert(str); //打印服务器那边返回来的字符串
}
}

}
}

</script>



//222.aspx页面的

//222.aspx.cs后台的加载事件里面
Response.Write("我是字符串");
Response.End();


最终xxx.aspx页面返回的str就是 我是字符串





IT回忆录 2011-08-23
  • 打赏
  • 举报
回复
不知道如何在c# winfrom中应用AJAX技术,

楼主可以在返回的字符串前加一个特殊字符如“@”等,既然返回的是一个字符串那么,就在C#中查找@就能找出来这段字符了
chp890310 2011-08-23
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 lmaohuanl 的回复:]
你这样strUrl不就是去拿一个网页么,》》》如果你想拿一个网页中的字符串的话用ajax了
[/Quote]
我的意思是:
我用客户端向服务端发送一个字符串,服务端再向客户端返回一个字符串,就是这个实现?
chp890310 2011-08-23
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 lmaohuanl 的回复:]
你这样strUrl不就是去拿一个网页么,》》》如果你想拿一个网页中的字符串的话用ajax了
[/Quote]
可以说明白点吗?具体写可以吗?初学入门。
LMAOhuaNL 2011-08-23
  • 打赏
  • 举报
回复
你这样strUrl不就是去拿一个网页么,》》》如果你想拿一个网页中的字符串的话用ajax了
chp890310 2011-08-23
  • 打赏
  • 举报
回复
就没有人解答下吗?

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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