Rumah > Soal Jawab > teks badan
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, 请问这是什么原因?有谁遇到过?