HTTP GET メソッドを使用してデータを取得したい。でも対応がおかしい
java.net.ProtocolException: Unexpected status line: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
修正方法は?
public JSONArray GetPost_sport(String token, String sport_type){
JSONArray jsonArray = null;
try {
URL url = new URL("http://o-two-sport.com/api/posts/?sport_type="+sport_type);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("Authorization","Token " +token);
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("Connection", "close");
conn.connect();
InputStream is = conn.getInputStream();
BufferedReader streamReader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
StringBuilder responseStrBuilder = new StringBuilder();
String inputStr;
while ((inputStr = streamReader.readLine()) != null)
responseStrBuilder.append(inputStr);
jsonArray = new JSONArray(responseStrBuilder.toString());
} catch (IOException | JSONException e) {
e.printStackTrace();
}
return jsonArray;
}