Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Sending files over HTTP  RSS feed

 
Jyotishman Pathak
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

This may be a dumb question, but could anyone tell me how to send files (e.g., XML) over HTTP using Java?

Thanks,
Jyoti
 
Jean-Sebastien Abella
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you need an http server, you can build it by yourself are use an existing one.
maybe apache is what you are looking for...
 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tell us more about your problem. Where are you sending files from and to? Are you working with a web application, such as one running on Tomcat?
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jean-Sebastien Abella:
you need an http server, you can build it by yourself are use an existing one.
maybe apache is what you are looking for...


Of course a http *server* doesn't *send* anything actively, it does "only" serve http requests. If you want to send files to a http server, I would use jakarta httpclient.

If you really want to serve http requests, one of the easiest ways to do so is using Jetty.
 
Jyotishman Pathak
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am writing some client code to talk to a Web service which accepts requests in XML as opposed to SOAP. Based on my request, it does some processing, and returns back the results again as an XML file.

Now, I know the IP of the machine hosting this service using which I can make a connection. Using this connetion, all I have to do is send the XML request, and in return receive an XML reply. The service is intelligent enough to figure out which method/function to execute based on the nature of the XML request.

I hope this clarifies my application scenario. If you can give any suggestions to do this, I would appreciate it.

Thanks,
Jyoti
 
Richard West
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,

Use the URLConnection class and connect to that URL and get the output stream for the URL and send the file over using streams. If a password is needed then use the Authenticator class to authenticate yourself
into that site.

Be careful about the authentication thing i mentioned because some HTTP servers may use a URL similar down the lines of the ftp URL where the username and password is part of the URL. For this you have to check out with some Http forums or people that run Http servers fo better information on it.

Richard West
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using UrlConnection is the low level solution. If you use Jakarta HttpClient, it will do a lot of the grunt work for you.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!