我需要登录网页,下载文件(出现在帖子之后),然后再次注销。
登录和注销都很好,但是当我尝试访问文件时遇到了一些麻烦。
在网络浏览器中,一旦我按下“确定”,我就会填写表格,它会显示“成功”的网页,并出现一个文件下载框。
当我通过 HTTP 客户端做同样的事情(通过 firebug 复制 FF 中使用的参数)时,我得到的只是 response.entity 是网页,但我在任何地方都看不到该文件。有人可以阐明我的问题吗?
这是我的代码(我意识到它目前不会保存响应,但如果它正在工作,我会期待一些长的二进制响应)
// get data
httpost = new HttpPost("https://webpage.com.au/folder/getfile.asp?param=2");
List <NameValuePair> nvps = new ArrayList <NameValuePair>();
nvps.add(new BasicNameValuePair("p1", "0"));
nvps.add(new BasicNameValuePair("p2", "03"));
nvps.add(new BasicNameValuePair("p3", "1"));
nvps.add(new BasicNameValuePair("p4", "6"));
nvps.add(new BasicNameValuePair("p5", "1"));
nvps.add(new BasicNameValuePair("p6", "2"));
nvps.add(new BasicNameValuePair("p7", "1"));
nvps.add(new BasicNameValuePair("p8", "0"));
nvps.add(new BasicNameValuePair("p9", "G"));
httpost.setEntity(new UrlEncodedFormEntity(nvps, Consts.UTF_8));
response = httpclient.execute(httpost);
entity = response.getEntity();
printResponse(entity);
System.out.println("Get file post: " + response.getStatusLine());
EntityUtils.consume(entity);
System.out.println("Post file get cookies:");
printCookies(httpclient);
和回应:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="language" content="en-us"/>
<meta name="robots" content="noindex, nofollow"/>
<meta http-equiv="Pragma" content="no-cache"/>
<meta http-equiv="Expires" content="-1"/>
<link rel="stylesheet" href="/css/style.css" type="text/css"/>
<script language="javascript">
var wasSubmitted = false;
function SingleSubmit ()
{
var OK = !wasSubmitted;
wasSubmitted = true;
return OK;
}
</script>
</head>
<body bgcolor="#FFFFFF" text="black" topmargin="0" leftmargin="0" marginwidth="0" marginheight="0">
<br>
<center><br><p class="center"></p><p class="center"></p><p class="center">getting file<br>
<script language=Javascript>
document.location = "TransSumExcel.asp";
</script>
</center>
</body>
</html>