오픈 날씨 api에서 어두운 하늘 api로 바뀌는 동안 연결에 문제가 있음을 발견했습니다.Android에서 HTTPS와 함께 InputStream을 사용할 수없는 이유는 무엇입니까?
간단히 말해서 API에서 JSON 응답을 얻고 개방형 날씨지도 api를 사용하면 모든 것이 잘 작동합니다. 이제 어두운 하늘 API를 대신 사용하기로 결정했습니다. 나는 항상 모든 것을 적용했지만 작동하지 않습니다.
아마도 https에 문제가 있습니까? (어두운 하늘의 api는 공개 날씨지도 api가 http-URL을 사용하는 https-URL을 사용합니다). 어쨌든
, 나는 여기
inputStream = connection.getInputStream();
에 IOException를 잡는 것은 내 클래스 :
import com.nymvno.hiob.prototyp_v30.Utils.Utils;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class WeatherHttpClient {
public String getWeatherData(String place) {
HttpURLConnection connection;
InputStream inputStream;
try {
connection = (HttpURLConnection) (new URL(Utils.BASE_URL + place)).openConnection();
connection.setRequestMethod("GET");
connection.setDoInput(true);
connection.setDoOutput(true);
connection.connect();
//Read the response
StringBuffer stringBuffer = new StringBuffer();
inputStream = connection.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
String line;
while ((line = bufferedReader.readLine()) != null) {
stringBuffer.append(line + "\r\n");
}
inputStream.close();
connection.disconnect();
return stringBuffer.toString();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
로그 오류 메시지를 게시 하시겠습니까? –
아무런 예외가 없다면 예외가 없다면 null이 반환되도록 전화를 끊습니다. – nymvno
예외가 없다면 왜 그런 질문이 있습니까? – EJP