使用HttpUnit发送带有POST请求的文件 [英] Sending file with POST request with HttpUnit

查看:213
本文介绍了使用HttpUnit发送带有POST请求的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

we have a REST service, which we would like to test. I thought about using HttpUnit for this purpose. We sent POST request to a resource URL and after receiving the request we retrieve the file from request. 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);

但出现以下错误:

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

关于如何将POST请求中的文件发送到我们服务器的任何建议?

Any suggestions how to send the file in the POST request to our server?

推荐答案

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

You might want to read the httpunit developer FAQ - just search httpunit's Unit Tests to find a fitting source code example:

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

这篇关于使用HttpUnit发送带有POST请求的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆