如何获取一个另一个网站页面的Json数据,

tianwei76 2016-03-05 08:28:42
已知该页面返回来的是 JSON 格式的数据,参数为ids:"",flex:"1" 方法POST 。如何在我的网站上获取数据。
...全文
1462 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
跨域需要在你的站点做代理,ajax请求代理页面而不是直接请求跨域页面,或者用yql转为jsonp数据 JSONP跨域访问在线代理API
vswen5 2016-03-05
  • 打赏
  • 举报
回复
public static String analysisUrl(String url){
		HttpURLConnection httpConnection = null;
		String output = "";
		try {
			URL targetUrl = new URL(url);
			httpConnection = (HttpURLConnection) targetUrl.openConnection();
			httpConnection.setDoOutput(true);
			httpConnection.setRequestMethod("GET");
			httpConnection.setRequestProperty("Content-Type",
					"application/json");
			InputStreamReader isr = new InputStreamReader(httpConnection
					.getInputStream(),"utf-8");
			BufferedReader responseBuffer = new BufferedReader(isr);
			output = responseBuffer.readLine();

		} catch (Exception e) {

		} finally {
			httpConnection.disconnect();
		}
		return output;
	}

52,778

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ajax
社区管理员
  • Ajax
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧