• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

HttpsURLConnection

 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I execute GET PING.PING HTTP/1.0 in a client code (Some GUI screen testing a host server) it works (200 OK), when doing it in my java code it doesn't. Can you help? Thanks

HttpsURLConnection con = (HttpsURLConnection)myurl.openConnection();
con.setDoOutput(true);
con.setDoInput(true);
//con.setRequestMethod("PUT");
//con.setRequestMethod("GET");
//System.out.println(con.getRequestMethod());

OutputStream out = con.getOutputStream();

out.write("GET PING.PING HTTP/1.0\r\n".getBytes());
out.flush();
out.close();
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The output stream in URLConnection and subclasses isn't for writing the request, it is for writing the body (i.e. form data).
What is myurl declared as?
You either want to create a URL that points to the resource PING.PING (whatever that is) or open up a socket to your server's port and write your request string ("GET PING.PING HTTP/1.0\r\n") and read the response.
 
Adam Teg
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok I will use the output stream to write the content. What can I use to write header information like Content-length: ?
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What content are your writing? It sounds like you just want to hit a URL to make sure a server is up and running.
If you want to mess with headers (and I'm not sure you do), have a look at http client. It has a richer interface for the particulars of HTTP.
 
Adam Teg
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am doing two things:
1) Ping the server to get a 200 ok so that I know it is up.

2) Send an XML data to the server.

I have NOT been successful with the any of it in my java program. I understand what you are saying - > only the content goes in when you ask for the getOutputStream(). But I am still confused where to put the ping command.
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let's work one problem at a time. In the first problem, you aren't really "ping"ing the server. We can't ping in java because we don't have that low of a level of socket. What you want to do is an HTTP GET. See this example. If it fails with an IOException, your server is down.
NOTE: the above applies only if your server is a web server, which I have assumed from your first post. If your server is NOT a web server, then you can't use HTTP/URLConnection to test it.
[ October 29, 2007: Message edited by: Joe Ess ]
 
Adam Teg
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is not a web server. It is a standalone app that listens to port 443. I got a solution to the ping issue..I think. Below is the code for anyone who cares. But I still can not send any data across. I have to set header information. Is there an example code someone knows.

Well javaranch does not want me to post the code???
 
Hold that thought. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic