rest-assured 上传文件,中文文件名乱码的问题解决

€¶婷姐儿♛ 测试交流2306字数 1147阅读模式

最近在用 rest-assured 测接口,比 httpClient 好用太多,但是在上传 文件名包含中文的时候,文件名发到后端是乱码,折腾了我大半天

我讲解一个问题,不会从计算机的起源开始叨逼叨半天废话一大堆文章源自玩技e族-https://www.playezu.com/192087.html

我只是负责解决问题,如果解决不了工作中的问题,
天天研究底层,研究 List 的迭代有 4 种写法,研究使用 lambda 可以让你少写几个字母也没啥卵用文章源自玩技e族-https://www.playezu.com/192087.html

技术只是一种解决问题的工具而已文章源自玩技e族-https://www.playezu.com/192087.html

为团队赋能,直接上代码,用下面的代码就可以决绝 上传文件名中包含中文的乱码问题:文章源自玩技e族-https://www.playezu.com/192087.html

package forBugs;
import io.restassured.config.HttpClientConfig;
import io.restassured.config.RestAssuredConfig;
import org.testng.annotations.Test;
import java.io.File;
import static io.restassured.RestAssured.given;
import static io.restassured.config.MultiPartConfig.multiPartConfig;
import static org.apache.http.entity.mime.HttpMultipartMode.BROWSER_COMPATIBLE;
public class C {
@Test
public void main() {
String s = given().config(RestAssuredConfig.config()
.httpClient(HttpClientConfig.httpClientConfig().httpMultipartMode(BROWSER_COMPATIBLE))
.multiPartConfig(multiPartConfig().defaultCharset("UTF-8")))
.multiPart(new File("C:\temp\1394356510\希尔顿.json"))
.header("Cookie", "JSESSIONID=1233")
.param("type", "json")
.when()
.post("http://alipay.com/upload")
.then()
.extract()
.response().asString();
System.out.println(s);
}
}
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>4.3.3</version>
</dependency>

就这样文章源自玩技e族-https://www.playezu.com/192087.html

软件测试分为接口测试功能测试文章源自玩技e族-https://www.playezu.com/192087.html 文章源自玩技e族-https://www.playezu.com/192087.html

玩技站长微信
添加好友自动发送入群邀请
weinxin
rainbow-shownow
玩技官方公众号
官方微信公众号
weinxin
PLAYEZU
 
评论  2  访客  1  作者  1
    • 玩技站长
      玩技站长

      欢迎指导。

      • wangbo
        wangbo 4

        测试

      匿名

      发表评论

      匿名网友
      确定