Giter Club home page Giter Club logo

Comments (5)

ashtum avatar ashtum commented on May 19, 2024

When you call prepare_payload(), the Content-Length and Transfer-Encoding field values are automatically adjusted based on the message body.

For instance:

http::request<http::string_body> req;
req.method(beast::http::verb::post);
req.body() = "body-contents";
req.prepare_payload(); // Content-Length set based on the body

Typically, you won't need to explicitly set Content-Length. However, if necessary, you can bypass calling prepare_payload(), and the values set in Content-Length and Transfer-Encoding will remain unchanged.

from beast.

NickKappy avatar NickKappy commented on May 19, 2024

When you call prepare_payload(), the Content-Length and Transfer-Encoding field values are automatically adjusted based on the message body.

For instance:

http::request<http::string_body> req;
req.method(beast::http::verb::post);
req.body() = "body-contents";
req.prepare_payload(); // Content-Length set based on the body

Typically, you won't need to explicitly set Content-Length. However, if necessary, you can bypass calling prepare_payload(), and the values set in Content-Length and Transfer-Encoding will remain unchanged.

Yes - thank you!

I am aware of this and we could ignore the line to set content-length even - but prepare_paylod seems to be ignoring the size of my body when I have it formatted in a json style

from beast.

ashtum avatar ashtum commented on May 19, 2024

If this is how you are setting the message body, it is incorrect:

req.set(http::field::body, "{\"username\":\"admin\", \"password\":\"admin"}");

You are actually setting a header field there.

This is how we set body content (assuming you are using http::request<http::string_body>):

req.body() = "body-contents";

from beast.

NickKappy avatar NickKappy commented on May 19, 2024

HAHA okay that explains so much - that resolves my issue thank you hahaha

from beast.

NickKappy avatar NickKappy commented on May 19, 2024

Issue resolved

from beast.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.