응답 코드 = 400 내 안드로이드 앱을 실행할 때, 브라우저와 우편함에서 동일한 URL을 테스트 할 때 응답 코드가 200입니다. 무엇이 잘못 되었나요? 이것은 요청 방법입니다응답 코드 400 OKHTTP
public static String getRequest(String myUrl) throws IOException {
InputStream is = null;
try {
URL url = new URL(myUrl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(30000 /*milliseconds*/);
conn.setConnectTimeout(20000 /*milliseconds*/);
conn.setRequestMethod("GET");
conn.setDoInput(true);
// Starts the query
conn.connect();
int response = conn.getResponseCode();
if (response != HttpURLConnection.HTTP_OK)
is = conn.getErrorStream();
else
is = conn.getInputStream();
Log.i(TAG, String.valueOf(response));
// Convert the InputStream into a string
return readStream(is);
// Makes sure that the InputStream is closed after the app is
// finished using it.
} finally {
if (is != null) {
is.close();
}
}
}
제가 도움이 필요하십니까?
로컬 서비스를 사용하십니까? –
아니요, 온라인 서버를 사용하고 있습니다 – chidinma
오류 400의 잘못된 요청입니다. 값을 확인하십시오. –