62,041
社区成员
发帖
与我相关
我的任务
分享
protected void Page_Load(object sender, EventArgs e)
{
string ss = HttpPost("http://yingyan.baidu.com/api/v3/track/addpoint", "{ \"ak:\"3iX0qo85OcqvWPIsuLKbDGoeAP8PAkVi\", \"service_id\": \"9819956\", \"entity_name\": \"001\", \"latitude\": \"40\", \"longitude\": \"122\", \"coord_type_input\": \"wgs84\", \"loc_time\": \"1466147899\" }");
this.Label1.Text = ss;
}
public static string HttpPost(string url, string body)
{
try
{
Encoding encoding = Encoding.UTF8;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.Accept = "text/html, application/xhtml+xml, */*";
request.ContentType = "application/json";
byte[] buffer = encoding.GetBytes(body);
request.ContentLength = buffer.Length;
request.GetRequestStream().Write(buffer, 0, buffer.Length);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
{
return reader.ReadToEnd();
}
}
catch (Exception ex)
{
return (ex.Message);
}
}