Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Receiving response from another server program

 
Velika Srbija
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to write a Servlet that will send request to some PHP page and then read the response generated by that PHP page? Response should contain attached "doc" file. Receiving that "doc" file is what I'm interested in.
Is there any guidelines on how to do such thing?
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or just use HttpURLConnection...
 
Velika Srbija
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and then what?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
 
Velika Srbija
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't even need HttpURLConnection in order to open a stream to the specified .doc file on the Internet if I know its absolute URL address.

But, in this case I have an PHP page that dinamically generates .doc file as a byte stream I want my servlet to record that stream. I'm not sure what datas I have to read before the stream starts, i.e. I don't know where the stream begins.?
Note: When I use browser, PHP response causes my browser to popup the "Save As" dialog.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Go read the documentation for HttpClient. It will allow you to simulate everything that a browser does from within your servlet code.
You could also retrieve it using the HttpUrlConnection as Jeroen mentioned.

Once you get it into your servlet, you can do whatever you want with it.
 
Velika Srbija
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK. Gonna try it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic