我正在尝试向应该返回 json 响应的网站发送 http 请求。问题是我没有得到 json 数据。但是当我将 url 粘贴到浏览器中时,它会显示 json 输出。我是新手。请帮忙。
这是我的代码
HttpClient client = new DefaultHttpClient();
String url="http://directclientvendors.com/news24/api/get.php?type=news";
HttpGet request = new HttpGet(url);
HttpResponse response;
response = client.execute(request);
BufferedReader br =
new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String line = "";
while(br.ready())
{
line+=br.readLine();
}
System.out.println("line "+line);