Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

URLConnection class : Very Urgent

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi to all,
It would be kind of you if anyone could let me know how this problem could be solved.
I am taking a http Url from the database for eg. http://cou10.mydomain.co.uk/dnrs/rprfrservlet
I need to send an Http request to the above address.
What i need to do is use the URL and URL Connection class for this purpose because right now i jad been specifying the url path by hand, but it need to be fetched from the database.
The actual URL where the request is to be sent is : http://cou10.netbenefit.co.uk/dnrs/rprfrservlet
The follwoing is the existing code and now i have to use URL Connection class to implement the same functionality.
existing one.
-------------
String shost = "cou10.mydomain.co.uk";
int iport = 80;
clientsocket = new Socket(shost,iport);
InputStream in = clientsocket.getInputStream();
OutputStream out = clientsocket.getOutputStream();
String url = "GET /dnrs/rprfrservlet?name="+s_name+"&requestid="+lreq_id+"&status="+lRPStatus+"&msg="+encodedMessage+"&trackingid="+sTrackingId+"&date="+sDate+"&command="+sCommand+HttpVersion;
byte buf[] = url.getBytes();
out.write(buf);
out.flush();
logDebug("After getting the bytes ** "+new java.util.Date());
StringBuffer response = new StringBuffer();
int chr;

logDebug("Before the while loop " +new java.util.Date());
while((chr=in.read())!=-1) {
response.append((char)chr);
}

String sResponse = response.toString();
System.out.println(sResponse);

NOW I WANT TO USE THE URL CONNECTION CLASS. HOW CAN THE SAME BE IMPLEMENTED USING THE URLCONNECTION CLASS.
Kindly LET ME KNOW,
Many Thanks
John
 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi John
Since you are using HTTP protocol use HttpURLConnection class and its methods.
Hope this helps.
Regards
sanj
 
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Use
URL url = new URL("url from database?"+"your querystring");
This will create the URL with the query parameters that you need to send with the header.
you can use the url.openConnection() which will return the URLConnection class. You can access the input stream and output stream of this class using setDoInput(boolean) and setDoOutput(boolean).
regards
 
reply
    Bookmark Topic Watch Topic
  • New Topic