繁体   English   中英

使用HttpUnit发送带有POST请求的文件

[英]Sending file with POST request with HttpUnit

我们有一个REST服务,我们想测试它。 我想过为此目的使用HttpUnit。 我们将POST请求发送到资源URL,并在收到请求后从请求中检索文件。 在我们的服务器代码中,我们有这样的东西:

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请求中的文件发送到我们的服务器的任何建议?

您可能想要阅读httpunit开发人员常见问题解答 - 只需搜索httpunit的单元测试以找到合适的源代码示例:

https://sourceforge.net/mailarchive/forum.php?thread_name=5051BBF6.70700%40bitplan.com&forum_name=httpunit-develop

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM