Post HtmlUnit FileUpload“;“尺寸未知”;

Post HtmlUnit FileUpload“;“尺寸未知”;,post,file-upload,htmlunit,Post,File Upload,Htmlunit,我有一个简单的表单,其中包含一个用于上传文件的输入字段和一个按钮 我尝试设置文件,单击按钮,但我从服务器得到一个响应,它告诉我“请求被拒绝,因为它的大小未知” 有人面临同样的问题或有什么建议吗 <form enctype="multipart/form-data" action="/WP/amp/filetransfer" method="post" name="form1" id="form1"> <input type="FILE" name="filee" encty

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

我尝试设置文件,单击按钮,但我从服务器得到一个响应,它告诉我“请求被拒绝,因为它的大小未知”

有人面临同样的问题或有什么建议吗

<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". 

最终WebClient WebClient=新WebClient();
最终HtmlPage=webClient.getPage(“www.example.com”);
最终HtmlForm form=page.getFormByName(“form1”);
最终HtmlFileInput=form.getInputByName(“文件”);
最终的HTMLButtoniInputButtonSubmit=form.getInputByName(“btnSubmit”);
输入.setData(读取(“e_201401145.xml”)//我有一个读取文件内容并以字节数组形式返回的方法
setValueAttribute(“e_201401145.xml”);
setContentType(“xml/text”);
最终HtmlPage responsePage=按钮提交。单击()//响应中有一条错误消息,告诉我:“请求被拒绝,因为它的大小未知”。

如果您手动上传文件,您给出了文件的路径,因此您不在此处执行操作??如果我只使用setData方法或setValueAttribute,服务器的行为就像我没有发送任何东西一样。您可以手动上传文件并在单击按钮之前检查源代码更改,当我手动设置文件的路径时,在源代码中看不到它,只有当我通过firebug浏览dom时,我才能看到它。