【发布时间】:2012-05-27 23:46:51
【问题描述】:
我们有一个 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 请求中的文件发送到我们的服务器有什么建议吗?
【问题讨论】:
标签: java rest testing http-unit