我正在尝试从公司的内部网络读取JSON,我已配置
System.setProperty("java.net.useSystemProxies", "true");
or
System.setProperty("https.proxyHost", "XX.XX.XX.XX");
System.setProperty("https.proxyPort", "XXXX");
我可以在互联网上公开阅读该API,而不会遇到任何问题
但是,当读取我公司的API而不是JSON时,它将返回HTML表
json = (java.lang.String) "<table border="0" cellpadding="4" cellspacing="0">
<thead>
<tr>
<th>status</th><th>message_code</th><th>devices</th><th>message</th></tr>
</thead>
<tbody>
<tr>
<td>1</td><td>SUCCESS</td><td>Array</td><td>Success</td></tr>
</tbody>
</table>
我用过
String json = IOUtils.toString(url, Charset.forName("UTF-8"));
和
URLConnection yc = oracle.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
我使用此代码解决了问题
URL url = new URL(sURL);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", "application/json");
BufferedReader br = new BufferedReader(new InputStreamReader(
(conn.getInputStream())));