Last active
August 29, 2015 13:57
-
-
Save kodiyan/9840506 to your computer and use it in GitHub Desktop.
Runnig and getting mocky response
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
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.net.HttpURLConnection; | |
import java.net.URL; | |
public class MockyCall { | |
private final String USER_AGENT; | |
public MockyCall (String userAgent) { | |
// super(); | |
this.USER_AGENT = userAgent; | |
} | |
public String getUSER_AGENT() { | |
return USER_AGENT; | |
} | |
public void sendPost(String serviceUrl) throws IOException { | |
long startTime = System.currentTimeMillis(); | |
System.out.println(serviceUrl); | |
URL obj = new URL(serviceUrl); | |
HttpURLConnection con = (HttpURLConnection) obj.openConnection(); | |
con.setRequestMethod("POST"); | |
con.setRequestProperty("User-Agent", USER_AGENT); | |
con.setRequestProperty("Accept-Language", "en-US,en;q=0.5"); | |
int responseCode = con.getResponseCode(); | |
System.out.println("\nSending 'POST' request to URL : " + serviceUrl); | |
System.out.println("Response Code : " + responseCode); | |
BufferedReader in = new BufferedReader(new InputStreamReader( | |
con.getInputStream())); | |
String inputLine; | |
StringBuffer response = new StringBuffer(); | |
while ((inputLine = in.readLine()) != null) { | |
response.append(inputLine); | |
} | |
in.close(); | |
long endTime = System.currentTimeMillis(); | |
System.out.println("\n Total Running Time: " + (endTime - startTime) | |
+ " milliseconds"); | |
// print result | |
System.out.println(response.toString()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment