求助

最近在用 rest assured 来做接口测试,其中有一个接口是需要上传文件的,但是发现上传的文件如果包含中文,服务端收到的文件名会变成乱码,导致服务端无法往后走,请教各位该怎么设置?
Query 如下:

File f = new File("testdata/20121115王刚11.doc");
        InputStream is = new FileInputStream(f);
        String fileName = f.getName();

        given().filter(new AllureRestAssured()).log().all()
                .config(config)
                .contentType("multipart/form-data;charset=utf-8")
                .queryParam("caseName", "apitest")
                .multiPart("documentations",
                        fileName, is, "application/msword")
        .when()
                .post("/caseAnalysis/addCase")

log 如下:

Request method: POST
Request URI:    http://u********.com/api/caseAnalysis/addCase?caseName=apitest
Proxy:          <none>
Request params: <none>
Query params:   caseName=apitest
Form params:    <none>
Path params:    <none>
Headers:        Accept=*/*
                Content-Type=multipart/form-data;charset=utf-8
Cookies:        <none>
Multiparts:     ------------
                Content-Disposition: form-data; name = documentations; filename = 20121115王刚11.doc
                Content-Type: application/msword

                <inputstream>
Body:           <none>

已解决

使用如下设置即可

RestAssured.config = RestAssuredConfig.config()
                .httpClient(HttpClientConfig.httpClientConfig()
                        .httpMultipartMode(HttpMultipartMode.BROWSER_COMPATIBLE));


↙↙↙阅读原文可查看相关链接,并与作者交流