Java 如何使用HtmlUnit以表单形式提交文件
我对这张表格有问题Java 如何使用HtmlUnit以表单形式提交文件,java,htmlunit,Java,Htmlunit,我对这张表格有问题 <form action="/incoming/Upload.cfg" enctype="multipart/form-data" method="post" onsubmit="return doSubmit();"> <table id="autoWidth" border="0" style="width: 100%;"> <tbody> <tr> <td class="h1"
<form action="/incoming/Upload.cfg" enctype="multipart/form-data" method="post" onsubmit="return doSubmit();">
<table id="autoWidth" border="0" style="width: 100%;">
<tbody>
<tr>
<td class="h1" colspan="4" id="t_title">
Резервная копия и Восстановление
</td>
</tr>
<tr>
<td class="blue" colspan="4"/>
</tr>
<tr>
<td class="Item" id="t_backup">
Сохранить:
</td>
<td colspan="3">
<input type="button" class="buttonBigL" name="Backup" value="Резервная копия" onclick="location.href='config.bin';"/>
</td>
</tr>
<tr>
<td class="Item" id="t_file">
Файл:
</td>
<td>
<input class="text" name="filename" type="file" size="20" onkeydown="return false"/>
</td>
<td>
<input name="Restore" type="submit" class="buttonBigL" id="Submit" value="Восстановить"/>
</td>
<td width="100%">
</td>
</tr>
<tr>
<td class="blue" colspan="4"/>
</tr>
</tbody>
</table>
</form>
什么也没发生代码在工作,过载消失了。但是我在spring容器中运行了测试,出于某种原因,我得到了这个错误
@RunWith(SpringRunner.class)
@SpringBootTest
如果你没有弹簧就跑,一切正常
htmlForm.<HtmlFileInput>getInputByName("filename").setValueAttribute(model);
htmlForm.<HtmlFileInput>getInputByName("filename").setContentType("multipart/form-data");
HtmlPage restore = htmlForm.getInputByName("Restore").click();
决定
@RunWith(SpringRunner.class)
@SpringBootTest
htmlForm.<HtmlFileInput>getInputByName("filename").setValueAttribute(model);
htmlForm.<HtmlFileInput>getInputByName("filename").setContentType("multipart/form-data");
HtmlPage restore = htmlForm.getInputByName("Restore").click();
webClient.getOptions().setTimeout(20000);
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
webClient.getOptions().setCssEnabled(false);
webClient.getOptions().setJavaScriptEnabled(true);
webClient.getOptions().setUseInsecureSSL(true);
webClient.getOptions().setRedirectEnabled(true);