我有asp.net应用程序,有1个网址打开报告, 我想尝试使用apache http client。,
导出此报告 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是报告页面, 并且会有一个按钮将报告导出到csv。,为此,我需要报告会话和控制ID, 经过一些研究,如果我点击导出到csv我会得到这个get方法 “/Reserved.ReportViewerWebControl.axd?ReportSession=(need this)Culture = 1033&amp; CultureOverrides = True&amp; UICulture = 1033&amp; UICultureOverrides = True&amp; ReportStack = 1&amp; ControlID =(需要此)&amp; OpType = Export&amp; FileName = Report +名称和安培; ContentDisposition = OnlyHtmlInline&安培;格式= CSV“
答案 0 :(得分:0)
@Test
public void submittingForm() throws Exception {
final WebClient webClient = new WebClient();
// Get the first page
final HtmlPage page1 = webClient.getPage("http://some_url");
// Get the form that we are dealing with and within that form,
// find the submit button and the field that we want to change.
final HtmlForm form = page1.getFormByName("myform");
final HtmlSubmitInput button = form.getInputByName("submitbutton");
final HtmlTextInput textField = form.getInputByName("userid");
// Change the value of the text field
textField.setValueAttribute("root");
// Now submit the form by clicking the button and get back the second page.
final HtmlPage page2 = button.click();
webClient.closeAllWindows();
}