带有内容部分中包含越南语字符的多部分的放心POST呼叫

问题描述 投票:0回答:1

我正在向具有包含越南语字符(例如á ư ..]的控件名称的内容主体的端点发送POST调用。

尽管请求已成功发送,但那些特殊字符已被???替换为ch?a ???c n?,在UI处应为chưa được nè

illlustration

public class MakeCostObject {
    RequestSpecBuilder requestSpec;
    public MakeCostObject() {
        requestSpec = new RequestSpecBuilder();
        String note = "chưa được nè";
        String status = "init";

        requestSpec.addMultiPart("note", note);
        requestSpec.addMultiPart("status", status);
    }

    public RequestSpecification createCost() {
        public RequestSpecification createCost () {
            return requestSpec.build();
        }
    }
}

这是POST请求,规范是通过createCost函数创建的。

response = given()
            .header("Content-type", "multipart/form-data")
            .header("Authorization", token)
            .when()
            .spec(spec)
            .post(APIPath.apiPath.POST_cost_upload);

response.then().assertThat().statusCode(201);

我尝试了另一个API(非表单数据),并且UI可以完美显示。

String str = "Tiếng việt";
Map<String, Object> body = new HashMap<>();

body.put("note", str);

given().spec(HeaderConfigs.headerwithnewToken())
        .when()
        .body(body)
        .patch("/costdetail/xxxx/");

如何配置编码或解决问题?

我的io.rest保证版本:4.2.0。

谢谢。

java rest-assured
1个回答
0
投票

我已经自己解决了这个问题。只需替换:

requestSpec.addMultiPart("note", note);

作者

requestSpec.addMultiPart(new MultiPartSpecBuilder(note).controlName("note").charset(Charsets.UTF_8).build());
© www.soinside.com 2019 - 2024. All rights reserved.