CopyPastor

Detecting plagiarism made easy.

Score: 0.8032258152961731; Reported for: String similarity Open both answers

Possible Plagiarism

Plagiarized on 2017-04-10
by Sanjog Shrestha

Original Post

Original - Posted on 2014-06-12
by Wasim Ahmed



            
Present in both answers; Present only in the new answer; Present only in the old answer;

try { // 1. create HttpClient HttpClient httpclient = new DefaultHttpClient(); // 2. make POST request to the given URL HttpPost httpPost = new HttpPost(url); String json = ""; // 3. build jsonObject JSONObject jsonObject = new JSONObject(); jsonObject.accumulate("foo1", "test"); jsonObject.accumulate("foo2", "test2"); // 4. convert JSONObject to JSON to String json = jsonObject.toString(); // ** Alternative way to convert Person object to JSON string usin Jackson Lib // ObjectMapper mapper = new ObjectMapper(); // json = mapper.writeValueAsString(person); // 5. set json to StringEntity StringEntity se = new StringEntity(json); // 6. set httpPost Entity httpPost.setEntity(se); // 7. Set some headers to inform server about the type of the content httpPost.setHeader("Accept", "application/json"); httpPost.setHeader("Content-type", "application/json"); // 8. Execute POST request to the given URL HttpResponse httpResponse = httpclient.execute(httpPost); // 9. receive response as inputStream inputStream = httpResponse.getEntity().getContent(); // 10. convert inputstream to string if(inputStream != null) result = convertInputStreamToString(inputStream); else result = "Did not work!"; } catch (Exception e) { Log.d("InputStream", e.getLocalizedMessage()); }

public static String POST( String username,String password){ String url=Constants.url_registration; InputStream inputStream = null; String result = ""; try { // 1. create HttpClient HttpClient httpclient = new DefaultHttpClient(); // 2. make POST request to the given URL HttpPost httpPost = new HttpPost(url); String json = ""; // 3. build jsonObject JSONObject jsonObject = new JSONObject(); jsonObject.accumulate("username", username); jsonObject.accumulate("password", password); // 4. convert JSONObject to JSON to String json = jsonObject.toString(); // ** Alternative way to convert Person object to JSON string usin Jackson Lib // ObjectMapper mapper = new ObjectMapper(); // json = mapper.writeValueAsString(person); // 5. set json to StringEntity StringEntity se = new StringEntity(json); // 6. set httpPost Entity httpPost.setEntity(se); // 7. Set some headers to inform server about the type of the content httpPost.setHeader("Accept", "application/json"); httpPost.setHeader("Content-type", "application/json"); // 8. Execute POST request to the given URL HttpResponse httpResponse = httpclient.execute(httpPost); // 9. receive response as inputStream inputStream = httpResponse.getEntity().getContent(); // 10. convert inputstream to string if(inputStream != null) result = convertInputStreamToString(inputStream); else result = "Did not work!"; } catch (Exception e) { Log.d("InputStream", e.getLocalizedMessage()); } // 11. return result return result; }

        
Present in both answers; Present only in the new answer; Present only in the old answer;