HttpURLConnection用GET方式请求一个http接口,接口返回的是一个json文件,报406错误
代码:
URL url = new URL(urlstr);
connection = (HttpURLConnection) url.openConnection();
connection.setConnectTimeout(50000);
connection.setRequestMethod("GET");
int responseCode = connection.getResponseCode();//这里返回406
if (responseCode == 200) {
is = connection.getInputStream();
......
}
如果设置connection.setRequestProperty("accept", "*/*");这句则会返回405,
请问这是什么原因?有谁遇到过?Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...