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();
}
|
请发表评论