• 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

Java URL - How to avoid "Length Required (411)" Error?

 
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Trying to do a simple POST Request, but am getting the error: "Length Required".

I've tried various approaches including not including the Content-Length (since Java may overwrite it) and issuing a zero-length Content-Length. Below, I am trying another method -- passing the length of the Request string.

Nothing I've tried thus far has worked. Still get the same "Length required".

Suggestions?



Prints: Length Required (411)


Suggestions?

Thanks,

- mike
 
Marshal
Posts: 4468
567
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How are you sending the content?  Typically you would do something like:and then write to the stream.
 
Mike London
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ron McLeod wrote:How are you sending the content?  Typically you would do something like:and then write to the stream.



Thanks...your suggestion led me to the solution.

-- mike
 
Saloon Keeper
Posts: 15443
362
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You shouldn't have to set the Content-Length header. This header is set automatically based on the content you've written to the message body. Of course, this means you have to write the message body, even if it's zero bytes:
 
reply
    Bookmark Topic Watch Topic
  • New Topic