• 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:
  • Devaka Cooray
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • paul wheaton
  • Paul Clapham
Saloon Keepers:
  • Piet Souris
Bartenders:

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

 
Bartender
Posts: 1973
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: 4935
624
VSCode Eclipse IDE 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: 1973
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
 
Bartender
Posts: 15743
368
  • 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