Loading

ASP.NET POST方式提交数据

protected void Page_Load(object sender, EventArgs e)
{
     
} private void getPostAddr(string lon, string lat) { string url = "http://www.ciensharp.com/api/addreq"; string postData = "postStr={" + string.Format("lon:{0},lat:{1},version:1.0.2", lon, lat) + "}&type=geocode"; Encoding encoding = Encoding.UTF8; byte[] data = encoding.GetBytes(postData); //准备请求 HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url); myRequest.Method = "POST"; myRequest.ContentType = "application/x-www-form-urlencoded"; myRequest.ContentLength = data.Length; Stream stream = myRequest.GetRequestStream(); //发送数据 stream.Write(data, 0, data.Length); stream.Close(); //获取数据 HttpWebResponse res = (HttpWebResponse)myRequest.GetResponse(); StreamReader sr = new StreamReader(res.GetResponseStream(), System.Text.Encoding.UTF8); string backstr = sr.ReadToEnd(); Response.Write(backstr); sr.Close(); res.Close(); }

 

posted @ 2012-09-19 18:02  The Mechanic  阅读(342)  评论(0编辑  收藏  举报