Android 앱에서 GET 요청을 보내려고하는데 다음 코드를 작성했지만 디버거를 사용하여 검사 할 때 SSL 오류가 발생했습니다. 을 감안할 때 는Java를 사용하여 GET 요청을 보내는 방법
private class AsyncLogin extends AsyncTask<String, String, String>
{
ProgressDialog pdLoading = new ProgressDialog(LoginActivity.this);
HttpsURLConnection conn;
URL url = null;
@Override
protected void onPreExecute() {
super.onPreExecute();
pdLoading.setMessage("\tLoading...");
pdLoading.setCancelable(false);
pdLoading.show();
}
@Override
protected String doInBackground(String... params) {
try {
url = new URL(params[0]);
} catch (MalformedURLException e) {
e.printStackTrace();
return "exception";
}
try {
conn = (HttpsURLConnection) url.openConnection();
conn.setReadTimeout(READ_TIMEOUT);
conn.setConnectTimeout(CONNECTION_TIMEOUT);
conn.setRequestMethod("GET");
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("Accept", "application/json");
conn.setRequestProperty("Origin","https://myserver.com");
conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36");
conn.setDoInput(true);
conn.setDoOutput(true);
conn.connect();
} catch (IOException e1) {
e1.printStackTrace();
return "exception";
}
try {
int response_code = conn.getResponseCode();
if (response_code == HttpsURLConnection.HTTP_OK) {
InputStream input = conn.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(input));
StringBuilder result = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
result.append(line);
}
return(result.toString());
}else{
return("unsuccessful");
}
} catch (IOException e) {
e.printStackTrace();
return "exception";
} finally {
conn.disconnect();
}
}
@Override
protected void onPostExecute(String result) {
pdLoading.dismiss();
if(result.equalsIgnoreCase("true"))
{
Intent intent = new Intent(LoginActivity.this,SuccessActivity.class);
startActivity(intent);
LoginActivity.this.finish();
}else if (result.equalsIgnoreCase("false")){
Toast.makeText(getApplicationContext(), "Invalid email or password", Toast.LENGTH_LONG).show();
} else if (result.equalsIgnoreCase("exception") || result.equalsIgnoreCase("unsuccessful")) {
Toast.makeText(LoginActivity.this, "OOPs! Something went wrong. Connection Problem.", Toast.LENGTH_LONG).show();
}
}
}
내 앱 번이 함수가 호출 끝 HTTP GET을 통해 로그인하는 데 사용 내 코드입니다. 당신이 HttpsURLConnection
캐스팅 이유는 무엇
org.apache.harmony.security.fortress.Engine.getInstance
아마도 어떤 종류의 오류가 발생했는지 알 수 있습니다. – stdunbar
@stdunbar 기록 된 오류없이 내 앱 프로세스가 종료됩니다. –
의심스러운 코드에'Log.d (TAG, your message .. ");를 추가하면 코드가 여전히 작동하는 곳을 찾을 수 있습니다. –