• Post Reply Bookmark Topic Watch Topic
  • New Topic

SetContentType  RSS feed

 
Richard Butterwood
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to do a http post to a web server passing an xml document.

What I need to do is set the ContentType and ContentLength plus any other stuff that will get sent in the MIME header.

What object do I set this against? Does anybody have a sample code that they could post?

Thanks,

Richard
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might want to use a library like Apache Jakarta Commons HttpClient to do this - that makes it much easier than trying to do it with the standard Java API.
[ November 08, 2005: Message edited by: Jesper de Jong ]
 
Richard Butterwood
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jesper.

I found the setRequestProperty on the HttpUrlConnection object. Looking at the webserver log file all the headers are being set correctly. The only problem I have now is the post.

I need for it to say "POST /APICALL HTTP/1.0", but the log file states "POST / HTTP/1.1". What property do I have to set to get APICALL inserted?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, that slash is the resource you want to post. / is the default, like a home page. The server might substitute in default.htm or index.htm. Try /APICALL on the end of your URL. The syntax is something like:

protocol://authority/resource

http://testserver/APICALL
 
Richard Butterwood
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, that worked great - appending APICALL to the URL.

Any clues on how to change HTTP 1.1 to HTTP 1.0? Will this affect anything?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!