在web应用中建立了一个aaa.ashx,代码仅是返回测试值,然后站点已部署到IIS。 public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Write(DateTime.Now.ToString() + "~~Hello World");
}
现在在winform中负荷取得Response.Write返回的内容呢?网上搜了好久都是说怎么利用ashx上传文件的....
{
context.Response.ContentType = "text/plain";
context.Response.Write(DateTime.Now.ToString() + "~~Hello World");
}
现在在winform中负荷取得Response.Write返回的内容呢?网上搜了好久都是说怎么利用ashx上传文件的....
HttpWebRequest request = HttpWebRequest.Create("http://xxx/aaa.ashx") as HttpWebRequest;
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
Stream resStream = response.GetResponseStream();
StreamReader sr = new StreamReader(resStream, System.Text.Encoding.Default); //编码可以改成别的ContentHtml.Text = sr.ReadToEnd();
连接aspx页面倒是可以获取全部的html。
找到了以前编写的抓取项目的代码,找到了区别,原来没有设置HttpWebRequest的CookieContainer,只需加一行代码即解决问题:webrequest.CookieContainer = new CookieContainer();
找到了以前编写的抓取项目的代码,找到了区别,原来没有设置HttpWebRequest的CookieContainer,只需加一行代码即解决问题:webrequest.CookieContainer = new CookieContainer();