码迷,mamicode.com
首页 > 其他好文 > 详细

都说了是随笔了还要什么标题

时间:2015-07-02 17:10:07      阅读:92      评论:0      收藏:0      [点我收藏+]

标签:

 

<script type="text/javascript">
$(function () {
$("#btnOK").click(function () {
$.ajax({
type: "POST",
url: "/Storage/CreateGeotable",
data: { name: "位置数据表", geotype: 1, is_published: 1, ak: "DqsjAlqpyHfX2igOzIxCeFwU" },
datatype: "json",
success: function (data) {
alert(data.length);
},
error: function () {
alert("error");
}
});
});
//
$("#btnGet").click(function () {
$.ajax({
type: "POST",
url: "/Storage/HttpGet",
data: { url: "http://api.map.baidu.com/geodata/v3/geotable/list", ak: "DqsjAlqpyHfX2igOzIxCeFwU" },
datatype: "json",
success: function (data) {
alert(data.length);
},
error: function () {
alert("error");
}
});
});
});
</script>

 

public JsonResult HttpPost(string name, int geotype, int is_published, string ak)
{
string url = "http://api.map.baidu.com/geodata/v3/geotable/create";
string postData = "name=" + name + "&geotype=" + geotype + "&is_published=" + is_published + "&ak=" + ak + ""; //
byte[] byteArray = Encoding.UTF8.GetBytes(postData);

HttpWebRequest objWebRequest = (HttpWebRequest)WebRequest.Create(url);
objWebRequest.Method = "POST";
objWebRequest.ContentType = "application/x-www-form-urlencoded";
objWebRequest.ContentLength = byteArray.Length;
Stream newStream = objWebRequest.GetRequestStream();
newStream.Write(byteArray, 0, byteArray.Length);
newStream.Close();

HttpWebResponse response = (HttpWebResponse)objWebRequest.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.Default);
string textResponse = sr.ReadToEnd(); // 返回的数据
return Json(url);
}

public string HttpGet(string url, string ak)
{
string getUrl = url + "?ak=" + ak;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(getUrl);
request.Method = "GET";
request.ContentType = "text/html;charset=UTF-8";

HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream myResponseStream = response.GetResponseStream();
StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
string retString = myStreamReader.ReadToEnd();
myStreamReader.Close();
myResponseStream.Close();

return retString;
}

都说了是随笔了还要什么标题

标签:

原文地址:http://www.cnblogs.com/niejun/p/4616384.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!