C# 网页aspx获取post的数据 protected void Page_Load(object sender, EventArgs e) { string str = Request.Form["loc"]; Response.Write(str); }这个代码没有问题啊,能取到post的数据。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不过,你的客户端要想接收到你返回的hello,还需要做些修改: protected void Page_Load(object sender, EventArgs e) { string str = Request.Form["loc"]; Response.Clear(); Response.ContentType = "text/plain"; Response.Write(str); Response.End(); } winform中确实可以获取到数据,但是我想在网页上获得winform post的值后进行一些操作,不过貌似都操作不了 <%@ WebHandler Language="C#" Class="CardDelete" %>using System;using System.Web;public class CardDelete : IHttpHandler{ public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; context.Response.Cache.SetCacheability(HttpCacheability.NoCache); string cardNo = context.Request["cardNo"]; context.Response.Write("成功"); } public bool IsReusable { get { return false; } }} public static string PostData(string ashx, string data) { try { var client = new WebClient(); client.Encoding = Encoding.UTF8; var url = ashx; if (data!="") { url +="?"+data; } var result = client.UploadString(url,data); return result; } catch (Exception ex) { return ""; } } var res =PostData("http://xxxxxx.com/GetCard.ashx", "id=5"); if(res=="成功"){} 第一段表示接口第二段封装了post 方法.第三段表示调用方法并且接收返回值..如果这你还是看不懂我也没办法了... 你没说你要操作什么啊。我其实想做的操作是 网页获取 post的值,然后写入文件或者写入数据库这种操作,不过我现在加上protected void Page_Load(object sender, EventArgs e) { string A = Request.Form["a"];//由winform中传给网页的参数用a标识 string B = Request.Form["b"]; //int C = Convert.ToInt32(A) + Convert.ToInt32(B); string C = B; C += A; if (C == "") { C = "Hello world!"; Response.Write(C);//将数据写到网页中 } else { FileStream fs = new FileStream("D:\\A.txt", FileMode.Append); StreamWriter sw = new StreamWriter(fs, Encoding.Default); sw.Write(C); sw.Close(); fs.Close(); Response.Write(C);//将数据写到网页中 Response.Write(A);//将数据写到网页中 g_str = C; } }加入这些操作,在winform端的post的返回就会失败。请帮忙看下。 这个是post端获取返回信息哇, string cardNo = context.Request["cardNo"]; context.Response.Write("成功");我想在这里就加入文件写入操作, FileStream fs = new FileStream("D:\\A.txt", FileMode.Append); StreamWriter sw = new StreamWriter(fs, Encoding.Default); sw.Write(C); sw.Close(); fs.Close();不过加上这段代码,post 就失败了 设置个断点跟踪一下aspx方,估计是写文件出错了。没有权限啥的 WPF中XAML如何绑定多级菜单的数据源? 最近刚接触WCF,有个疑问请教 如何从网页中得到想要的内容 请大家对这个问题给个算法意见,合理都有分! 自己建立的usercontrol,怎样不让用户可以在设计环境中改变其大小 C#字符串截取问题应该怎么截取 ^o^ 关于C#绘制字符串的问题.... 关闭IE浏览器时有没有事件触发? 有个初始化报错的问题 visual studio安装问题 求助贴,想用C# TreeView控件来实现Linux目录树显示,如何实现 WebKit.WebKitBrowser无反应
protected void Page_Load(object sender, EventArgs e)
{
string str = Request.Form["loc"]; Response.Clear();
Response.ContentType = "text/plain";
Response.Write(str);
Response.End();
}
<%@ WebHandler Language="C#" Class="CardDelete" %>using System;
using System.Web;public class CardDelete : IHttpHandler
{ public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Cache.SetCacheability(HttpCacheability.NoCache); string cardNo = context.Request["cardNo"]; context.Response.Write("成功");
} public bool IsReusable
{
get
{
return false;
}
}} public static string PostData(string ashx, string data)
{
try
{
var client = new WebClient();
client.Encoding = Encoding.UTF8;
var url = ashx;
if (data!="")
{
url +="?"+data;
}
var result = client.UploadString(url,data);
return result;
}
catch (Exception ex)
{
return "";
}
} var res =PostData("http://xxxxxx.com/GetCard.ashx", "id=5");
if(res=="成功")
{
}
第二段封装了post 方法.
第三段表示调用方法并且接收返回值..
如果这你还是看不懂我也没办法了...
你没说你要操作什么啊。我其实想做的操作是 网页获取 post的值,然后写入文件或者写入数据库这种操作,不过我现在加上protected void Page_Load(object sender, EventArgs e)
{
string A = Request.Form["a"];//由winform中传给网页的参数用a标识
string B = Request.Form["b"];
//int C = Convert.ToInt32(A) + Convert.ToInt32(B);
string C = B;
C += A; if (C == "")
{
C = "Hello world!";
Response.Write(C);//将数据写到网页中
}
else
{
FileStream fs = new FileStream("D:\\A.txt", FileMode.Append);
StreamWriter sw = new StreamWriter(fs, Encoding.Default);
sw.Write(C);
sw.Close();
fs.Close();
Response.Write(C);//将数据写到网页中
Response.Write(A);//将数据写到网页中
g_str = C;
}
}加入这些操作,在winform端的post的返回就会失败。请帮忙看下。
string cardNo = context.Request["cardNo"]; context.Response.Write("成功");
我想在这里就加入文件写入操作, FileStream fs = new FileStream("D:\\A.txt", FileMode.Append);
StreamWriter sw = new StreamWriter(fs, Encoding.Default);
sw.Write(C);
sw.Close();
fs.Close();不过加上这段代码,post 就失败了