Skip to content

Instantly share code, notes, and snippets.

@SriMaddy
Last active March 29, 2017 05:26
Show Gist options
  • Save SriMaddy/3b6b508229e41e29ea35aa5b0f7733c0 to your computer and use it in GitHub Desktop.
Save SriMaddy/3b6b508229e41e29ea35aa5b0f7733c0 to your computer and use it in GitHub Desktop.
https call via volley
⁠⁠⁠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