RestClient client = new RestClient("http://www.example.com/demo.php"); //Write your url here client.addParam("Name", "Bhavit"); //Here I am adding key-value parameters client.addParam("Age", "23"); client.addHeader("content-type", "application/json"); // Here I am specifying that the key-value pairs are sent in the JSON format try { String response = client.executePost(); // In case your server sends any response back, it will be saved in this response string. } catch (Exception e) { e.printStackTrace(); }
RestClient client = new RestClient("http://www.example.com/demo.php"); //Write your url here client.addParam("Name", "Bhavit"); //Here I am adding key-value parameters client.addParam("Age", "23"); client.addHeader("content-type", "application/json"); // Here I am specifying that the key-value pairs are sent in the JSON format try { String response = client.executePost(); // In case your server sends any response back, it will be saved in this response string. } catch (Exception e) { e.printStackTrace(); }
public String communicateWithServer(String xmlInput) { String response = null; String webServiceUrl = "your-server-url"; RestClient client = new RestClient(webServiceUrl); client.setJSONString(xmlInput); client.addHeader("Content-Type", "text/xml"); try { client.execute(RequestMethod.POST); if (client.getResponseCode() != 200) { // handle error here } response = client.getResponse(); } catch (Exception e) { e.printStackTrace(); } return response; }
String webServiceUrl = "your-service-url"; RestClient client = new RestClient(webServiceUrl); String serverResponse = ""; String inputJsonString = "{" + " \"grant_type\" : \"password\"," + " \"username\" : \"perry.marange@zmod.co\"," + " \"password\" : \"password\"" + "}"; client.setJSONString(inputJsonString); client.addHeader("Content-Type", "appication/json"); // if required try { client.execute(RequestMethod.POST); if (client.getResponseCode() != 200) { // response error } else { // the response from server serverResponse = client.getResponse(); } } catch (Exception e) { // handle error }