3
我們有一個REST服務,我們要測試它。我想過爲此使用HttpUnit。 我們發送POST請求到一個資源的URL,並收到請求後,我們從請求中檢索文件。在我們的服務器代碼,我們有這樣的事情:使用POST請求發送帶有HttpUnit的文件
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請求中的文件發送到我們的服務器?