我有 asp.net 应用程序,有 1 个 url 来打开报告,我想尝试使用 apache http 客户端导出此报告。,
DefaultHttpClient httpclient = new DefaultHttpClient();
try {
/* POST login */
HttpPost httpost = new HttpPost("http://localhost:80");
List <NameValuePair> nvps = new ArrayList <NameValuePair>();
nvps.add(new BasicNameValuePair("login", "e"));
nvps.add(new BasicNameValuePair("pw", "password"));
httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
HttpResponse response = httpclient.execute(httpost);
HttpEntity entity = response.getEntity();
System.out.println("Login form get: " + response.getStatusLine());
EntityUtils.consume(entity);
/* get content*/
HttpGet httpget = new HttpGet("http://localhost:80/Report);
System.out.println("executing request " + httpget.getURI());
// Create a response handler
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String responseBody = httpclient.execute(httpget, responseHandler);
System.out.println("----------------------------------------");
System.out.println(responseBody);
System.out.println("----------------------------------------");
} finally {
// When HttpClient instance is no longer needed,
// shut down the connection manager to ensure
// immediate deallocation of all system resources
httpclient.getConnectionManager().shutdown();
}
}
假设 localhost:80/Report 是报告页面,并且会有 1 个按钮将报告导出到 csv。,为此,我需要报告会话和控制 ID,并且经过一些研究,如果我单击导出到 csv,我将获得此获取方法 "/Reserved.ReportViewerWebControl.axd?ReportSession=(need this)Culture=1033&CultureOverrides=True&UICulture=1033&UICultureOverrides=True&ReportStack=1&ControlID=(need this)&OpType=Export&FileName=Report+Name&ContentDisposition =OnlyHtmlInline&Format=CSV"
- 如何获取报告会话和控件 ID?
- 如何导出报告?我已经将 HttpGet 更改为同一会话中的 get 方法并控制 id,但仍然无法正常工作..
我这样做对吗?因为我是一个全新的 apache httpclient ..