Please guide me to find the problem in this code, when i use url with HTTP then it works fine but with HTTPS it's giving problem.I have googled but couldn't find a solution. It would be appreciable if someone guide me to save my time Thanks
public String doRequest() {
String serverUrl = Constants.BASE_URL + mAction;
Log.d("usm_serverUrl",serverUrl);
if (mParams != null) {
serverUrl += "?" + mParams;
}
Log.d("usm_serverUrl",serverUrl);
try {
URL url = new URL(serverUrl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("User-Agent", "application/json");
// conn.setRequestMethod("GET");
if(conn.getResponseCode() == HttpsURLConnection.HTTP_OK){
// Do normal input or output stream reading
Log.d("usm_requestCode","Successful");
}
else {
Log.d("usm_requestCode","Failed");
// response = "FAILED"; // See documentation for more info on response handling
}
//HttpURLConnection conn = (HttpURLConnection) url.openConnection();
InputStream in = new BufferedInputStream(conn.getInputStream());
Log.d("debug", "get-url: " + serverUrl);
String response = IOUtils.toString(in, "UTF-8");
Log.d("debug", "get-url: " + serverUrl + "\n post-response: " + response);
return response;
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
Aucun commentaire:
Enregistrer un commentaire