我有 REST Web 服务,它给了我 json 数据,我从 android 使用该 json 数据,现在我想从 ASP 使用它,我试过这个:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// corrected to WebRequest from HttpWebRequest
WebRequest request = WebRequest.Create("http://localhost:8080/test2/eattel/cities");
request.Method = "GET";
request.ContentType = "application/json; charset=utf-8";
//get response-stream, and use a streamReader to read the content
using (Stream s = request.GetResponse().GetResponseStream())
{
using (StreamReader sr = new StreamReader(s))
{
var jsonData = sr.ReadToEnd();
//decode jsonData with javascript serializer
}
}
}
}
我有空白页,请问为什么?如何解决?也许我得到了结果,但我没有打印它?提前致谢