Last active
March 29, 2017 05:26
-
-
Save SriMaddy/3b6b508229e41e29ea35aa5b0f7733c0 to your computer and use it in GitHub Desktop.
https call via volley
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void NetworkCall() { | |
RequestQueue queue; | |
StringRequest stringRequest; | |
queue = Volley.newRequestQueue(getApplicationContext(),new HurlStack(null, createSslSocketFactory())); | |
stringRequest = new StringRequest(Request.Method.POST, "https://www.thehellofood.com/restaurantapi/getFoodItems", new Response.Listener<String>() { | |
@Override | |
public void onResponse(String response) { | |
try { | |
Log.e("response", response); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
, new Response.ErrorListener() { | |
@Override | |
public void onErrorResponse(VolleyError error) { | |
Log.e("logging error", error.toString()); | |
} | |
}) { | |
@Override | |
protected HashMap<String, String> getParams() { | |
HashMap<String, String> params = new HashMap<String, String>(); | |
params.put("location_id","1"); | |
return params; | |
} | |
}; | |
queue.add(stringRequest); | |
} | |
private static SSLSocketFactory createSslSocketFactory() { | |
TrustManager[] byPassTrustManagers = new TrustManager[]{new X509TrustManager() { | |
public X509Certificate[] getAcceptedIssuers() { | |
return new X509Certificate[0]; | |
} | |
public void checkClientTrusted(X509Certificate[] chain, String authType) { | |
} | |
public void checkServerTrusted(X509Certificate[] chain, String authType) { | |
} | |
}}; | |
SSLContext sslContext = null; | |
SSLSocketFactory sslSocketFactory = null; | |
try { | |
sslContext = SSLContext.getInstance("TLS"); | |
sslContext.init(null, byPassTrustManagers, new SecureRandom()); | |
sslSocketFactory = sslContext.getSocketFactory(); | |
} catch (NoSuchAlgorithmException e) { | |
e.printStackTrace(); | |
Log.e("dfdsf",e.toString()); | |
} catch (KeyManagementException e) { | |
Log.e("dfsdfd", e.toString()); | |
} | |
return sslSocketFactory; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment