使用HttpUnit发送POST请求上传文件

3
我们有一个 REST 服务需要测试,我考虑使用 HttpUnit 进行测试。 我们向资源 URL 发送 POST 请求,在接收请求后,我们从请求中检索文件。 在我们的服务器代码中,类似下面这样:
MultipartFormData body = request().body().asMultipartFormData();
FilePart file = body.getFile("upfile");
File pictureFile = file.getFile();

在我的测试中,我写了:

WebConversation wc = new WebConversation();
WebRequest wr = new PostMethodWebRequest("http://linkToOurResource");
File f = new File("testFile.jpg");
wr.selectFile("upfile", f, "multipart/form-data;");
    WebResponse response = wc.getResponse(wr);

但是我遇到了以下错误:
Test functional.AcceptanceTests.testAddingNewClient failed: Parameter 'upfile' is not a file parameter and may not be set to a file value.

有什么建议可以在POST请求中向我们的服务器发送文件吗?
1个回答

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接