Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String url = "http:localhost:8080/RestPractice/rest/UserService/path";
- URL obj = new URL(url);
- HttpURLConnection con = (HttpURLConnection) obj.openConnection();
- con.setRequestMethod("POST");
- con.setRequestProperty("User-Agent", USER_AGENT);
- Gson gsonObj = new Gson();
- Map<String, String> inputMap = new HashMap<String, String>();
- inputMap.put("name", "somename");
- String jsonStr = gsonObj.toJson(inputMap);
- System.out.println(jsonStr);
- con.setDoOutput(true);
- DataOutputStream wr = new DataOutputStream(con.getOutputStream());
- wr.writeBytes(jsonStr);
- wr.flush();
- wr.close();
- int responseCode = con.getResponseCode();
- System.out.println("Response Code : " + responseCode);
- BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
- String output;
- StringBuffer response = new StringBuffer();
- while ((output = in.readLine()) != null) {
- response.append(output);
- }
- in.close();
- System.out.println(response.toString());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement