• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Post to an URL using HttpURLConnection

 
Nagavarapu Shashikant
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers,

I want to post some xml content and add an attachment (may be multiple files - docs etc) to an URL. This is to test a webservice call. I am using HttpURLConnection to achieve this and wirting the file contents to the output stream. This does not work as I am getting a 500 error. Please suggest me how do I post the files as attachment as well as the xml content(mandatory post content) to the stream(Output Stream).

Regards
Shashikant
 
Rob Spoor
Sheriff
Pie
Posts: 20610
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use Apache Commons HTTP Client instead.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A 500 error is "Internal Server Error" so your code may be working but the webservice isn't.

Is this a SOAP web service you are calling? Where are you getting information on what the service wants to see?

Bill
 
Nagavarapu Shashikant
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bill,

This is not a SOAP call. The webservice is up and i want to lookup the service using java code.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does "lookup the service" mean? Are you trying to access to service, or its WSDL, or something else?

Also, when you're posting to the service, are you certain that the XML you're sending is exactly what the service is expecting?

And finally, as Bill said a 500 signifies a server error. If available, check the server logs for any error massages.
 
Nagavarapu Shashikant
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have checked the service spec and it asks for a specific format of xml. I have prepared the xml file and reading data from it. The service just returns a service code 200 if all is fine..
 
Nagavarapu Shashikant
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The other problem i am facing is how to send attachments using the stream. I have multi pdf documents which i need to send.. please update me with any ideas.
 
Rob Spoor
Sheriff
Pie
Posts: 20610
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rob Prime:
Use Apache Commons HTTP Client instead.

Have you tried that one already? It's PostMethod can take call the setRequestEntity method with an instance of MultipartRequestEntity. This in turn can be created using a Part[], and guess what - there are subclasses of Part called FilePart and StringPart.
[ October 06, 2008: Message edited by: Rob Prime ]
 
Nagavarapu Shashikant
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,

I will try this.. I was trying the attachments posting using Java mail API..
 
Rob Spoor
Sheriff
Pie
Posts: 20610
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That doesn't make sense to me. Email is totally unrelated to HTTP(S).

Also, could you please check our naming policy?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic