简体   繁体   English

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

[英]Sending file with POST request with HttpUnit

we have a REST service, which we would like to test. 我们有一个REST服务,我们想测试它。 I thought about using HttpUnit for this purpose. 我想过为此目的使用HttpUnit。 We sent POST request to a resource URL and after receiving the request we retrieve the file from request. 我们将POST请求发送到资源URL,并在收到请求后从请求中检索文件。 In our server code we have something like this: 在我们的服务器代码中,我们有这样的东西:

MultipartFormData body = request().body().asMultipartFormData();
FilePart file = body.getFile("upfile");
File pictureFile = file.getFile();

In my test I wrote: 在我的测试中,我写道:

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);

but I'm getting the following error: 但我收到以下错误:

Test functional.AcceptanceTests.testAddingNewClient failed: Parameter 'upfile' is not a file parameter and may not be set to a file value.

Any suggestions how to send the file in the POST request to our server? 有关如何将POST请求中的文件发送到我们的服务器的任何建议?

You might want to read the httpunit developer FAQ - just search httpunit's Unit Tests to find a fitting source code example: 您可能想要阅读httpunit开发人员常见问题解答 - 只需搜索httpunit的单元测试以找到合适的源代码示例:

https://sourceforge.net/mailarchive/forum.php?thread_name=5051BBF6.70700%40bitplan.com&forum_name=httpunit-develop 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