Giter Site home page Giter Site logo

jodd-http set body encoding about jodd HOT 2 CLOSED

southfly avatar southfly commented on June 2, 2024
jodd-http set body encoding

from jodd.

Comments (2)

neroux avatar neroux commented on June 2, 2024

https://oblac.github.io/jodd-site/javadoc/jodd/http/HttpBase.html#body-java.lang.String-

Sets raw body content and discards all form parameters. Important: body string is in RAW format, meaning, ISO-8859-1 encoding. Also sets "Content-Length" parameter. However, "Content-Type" is not set and it is expected from user to set this one.

You'd want to use bodyText() instead.

from jodd.

southfly avatar southfly commented on June 2, 2024

thanks,

        // post json
        String ram = "{\"name\":\"你好(Chinese)\",\"age\":28}";
        HttpRequest res = HttpRequest
                .post("https://test.hisouth.cn/http/postJson")
//                .contentType("application/json", StringPool.UTF_8)
//                .body(ram) // it will be convert to ISO_8859_1 always
//                .body(new String(ram.getBytes(), StringPool.ISO_8859_1))
                .bodyText(ram, "application/json", StringPool.UTF_8);
//                    .contentTypeJson();
        String bodyText = res.send().charset(StringPool.UTF_8).bodyText();
        System.out.println(bodyText); // ok, {"name":"你好(Chinese)","age":28}
        // i didn't change original charset to ISO_8859_1

for i didn't change original charset to 'ISO_8859_1' before the request send.

from jodd.

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.