ASP.NET post访问外网接口获取数据
方法一:
string postData = string.Format("a=1&b=2"); //post传递参数
Stream outstream = null;
Stream instream = null;
StreamReader sr = null;
HttpWebResponse response = null;
HttpWebRequest request = null;
Encoding encoding = Encoding.Default;
byte[] data = encoding.GetBytes(postData);
// 准备请求
// 设置参数
request = WebRequest.Create("http://www.baidu.com") as HttpWebRequest;
CookieContainer cookieContainer = new CookieContainer();
request.CookieContainer = cookieContainer;
request.AllowAutoRedirect = true;
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
outstream = request.GetRequestStream();
outstream.Write(data, 0, data.Length);
outstream.Close();
//发送请求并获取相应回应数据
相关文档:
我主要用来跟踪后台的一些情况,我用的是一个第三方插件,很好用的
log4net
具体使用如下:
Web.config配置:
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
</configSections>
<log4net>
&nbs ......
c#(或vb.net)程序改进
1、使用值类型的ToString方法
在连接字符串时,经常使用"+"号直接将数字添加到字符串中。这种方法虽然简单,也可以得到正确结果,但是由于涉及到不同的数据类型,数字需要通过装箱操作转化为引用类型才可以添加到字符串中。但是装箱操作对性能影响较大,因为在进行这类处理时,将在托管堆中 ......
在Asp.net中,从A页面中弹出B页面,在B页面中选择数据后,关闭并将数据更新到A页面,是一种常用的方式。只是我对Javascript不熟悉,所以捣鼓了一下午,终于有了一点成绩。
测试项目有两个页面:Default.aspx及Default2.aspx,在Default.aspx页面上有一个TextBox1及一个Button1,Button1用于触发Default2.aspx,TextBox ......
asp.net 网页传参的几种常用方式
第一种:QueryString
//将源页面start.aspx中的lable 和textbox中的内容传到end.aspx页面中 并在其lable 和textbox中显示传过来的内容
源页面代码:
protected void Button1_Click(object sender, EventArgs e)
{
& ......
asp.net输出 png 32位 图像,带透明alpha。
// pngtest.htm
<html>
<head></head>
<body bgColor="gray">
<img src="png.ashx" />
</body>
</html>
// png.ashx
<%@ WebHandler Language="C#" Class="Png" %>
using System.Web;
public class Png : IHtt ......