Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get and Post Response Times

Status
Not open for further replies.

JohnnyProd

Technical User
Sep 25, 2001
12
0
0
US
I'm trying to write a small app which will measure the resposen time of our application. To do this I have created a serries of Get() and Post() methods which grab the time in two places, take the difference, and write the info out to a file. What I am now wondering is if there is a better way for me to be doing POSTs and GETs. This is a example off my POST method:

public String post(String myURL, String[][] nameValuePairs){
String response = "";
try
{
String startDate = new Date().toString();
long startTime = System.currentTimeMillis();

String urlName = rootURL + myURL;
String postData ="";
BufferedReader in;

URLConnection connection;
URL homeURL = new URL(urlName);
connection = homeURL.openConnection();
connection.setDoInput( true );
connection.setDoOutput( true );
connection.setUseCaches( false );
connection.setRequestProperty("Accept", "*/*");
connection.setRequestProperty("Referer", this.referer);
connection.setRequestProperty("Accept-Language", "en-us");
connection.setRequestProperty("User-Agent", "");
connection.setRequestProperty("content-type", "application/x- connection.setRequestProperty("Cookie", this.cookie);
((HttpURLConnection)connection).setRequestMethod("POST");
PrintWriter pw = new PrintWriter(connection.getOutputStream() );
for (int i = 0; i < nameValuePairs.length; i++)
{
postData += (nameValuePairs[0] + &quot;=&quot;);
for (int j = 1; j < nameValuePairs.length; j++)
{
postData += (nameValuePairs[j] + &quot;&&quot;);
}
}
pw.write((postData));
pw.close();
String tmpString = &quot;&quot;;
try
{
in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
while ((tmpString = in.readLine()) != null)
{
response += tmpString + '\n';
}
in.close();
} catch(FileNotFoundException myFileNotFoundException){
myFileNotFoundException.printStackTrace(System.out);
}
if ((connection.getHeaderField(7) != null) && (connection.getHeaderFieldKey(7).compareTo(&quot;Set-Cookie&quot;) == 0))
{
this.cookie = connection.getHeaderField(7);
}
long responseTime = (System.currentTimeMillis() - startTime);
...



Using this method for POSTing, I can't really determin when the request os being sent and at what exact point the response has been finished. Any ideas people? Is there a better way for me to be going about this?
 
You might think about doing a small proxy to
sit between your client and the server.
In this way you can see
the exact post and response times. Just take one of the
many http server examples from a book and change it
to pass the response back and forth.
In you client app you need to set it up to go through
your proxy.
System.getProperties().put(&quot;proxySet&quot;,&quot;true&quot;);
System.getProperties().put(&quot;proxyHost&quot;,&quot;ip address of server&quot;);
System.getProperties().put(&quot;proxyPort&quot;,&quot;any port you to set proxy&quot;);


 
Thanks for the tip, I will definately look into that.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top