HtmlUnit FileUpload“大小未知”

时间:2014-02-26 09:12:09

标签: post file-upload htmlunit

我有一个简单的表单,其中包含用于文件上传的输入字段和一个按钮。

我尝试设置文件,点击按钮但我收到服务器的回复,告诉我“请求被拒绝,因为它的大小未知”。

任何人遇到同样的问题或有建议吗?

<form enctype="multipart/form-data" action="/WP/amp/filetransfer" method="post" name="form1" id="form1">
  <input type="FILE" name="filee" enctype="multipart/form-data" style="caption:'abc'">
  <input type="button" name="btnSubmit"  value="Upload File" onclick="form1.submit();">
</form>

final WebClient webClient = new WebClient(); 
final HtmlPage page = webClient.getPage("www.example.com"); 
final HtmlForm form = page.getFormByName("form1");

final HtmlFileInput input = form.getInputByName("filee"); 
final HtmlButtonInput buttonsubmit = form.getInputByName("btnSubmit");

input.setData(read("e_201401145.xml"));//i have a method which reads the file content and returns as byte array
input.setValueAttribute("e_201401145.xml");
input.setContentType("xml/text"); 
final HtmlPage responsePage = buttonsubmit.click(); //Response has the error message which tells me: "the request was rejected because it's size is unknown". 

0 个答案:

没有答案