用HttpClient 访问页面Session 保持的问题。。
--------------------编程问答-------------------- 用 HttpContext 试试:// Create a local instance of cookie store--------------------编程问答-------------------- 嗯,得带上cookie --------------------编程问答-------------------- 空指针了!
CookieStore cookieStore = new BasicCookieStore();
// Create local HTTP context
HttpContext localContext = new BasicHttpContext();
// Bind custom cookie store to the local context
localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
HttpGet httpget = new HttpGet("http://www.google.com/");
System.out.println("executing request " + httpget.getURI());
// Pass local context as a parameter
HttpResponse response = httpclient.execute(httpget, localContext);
<textarea width="100%" rows="7" readonly>java.lang.NullPointerException
at jsp_servlet._TJTAX_NET._NetLevy._NetQuery._TicketUse.__edit._jspService(__edit.java(Compiled Code))
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java(Compiled Code))
at javax.servlet.http.HttpServlet.service(HttpServlet.java(Compiled Code))
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java(Compiled Code))
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java(Compiled Code))
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java(Inlined Compiled Code))
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java(Inlined Compiled Code))
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java(Compiled Code))
at weblogic.security.service.SecurityServiceManager.runAs(SecurityServiceManager.java(Compiled Code))
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java(Compiled Code))
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java(Compiled Code))
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java(Compiled Code))
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java(Compiled Code))
</textarea> --------------------编程问答-------------------- 另外你要带上JESSIONID
// if account logged in, add session to header
request.setHeader("JESSIONID", xxx); --------------------编程问答-------------------- 也还是不行。
HttpClient httpClient = new DefaultHttpClient();
CookieStore cookieStore = new BasicCookieStore();
HttpContext localContext = new BasicHttpContext();
localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
HttpGet httpget = new HttpGet("http://202.99.102.23/TJTAX_NET/NetLevy/NetQuery/TicketUse/index.jsp");
HttpResponse response = httpClient.execute(httpget, localContext);
String result=EntityUtils.toString(response.getEntity());
System.out.println(result);
System.out.println("--------------------------------------------------------------------------------------");
httpget = new HttpGet("http://202.99.102.23/servlet/com.appinf.bus.TaskBus?_TaskID=tjtax.declevy.NetQuery.TicketQuery.si.C_UseTicketQuerySI_siTicketQuery&_SIVO=tjtax.declevy.NetQuery.TicketQuery.vo.C_UseTicketQueryVO&_SessionName=%2FTJTAX_NET%2FNetLevy%2FNetQuery%2FTicketUse%2Findex.jsp&cxfs=1&S_INVOICECODE=&S_TICKETCODE=&S_TICKETCHECKCODE=212001304013099160045971&S_KPJE=3454.76");
response = httpClient.execute(httpget, localContext);
result=EntityUtils.toString(response.getEntity());
System.out.println(result);
System.out.println("--------------------------------------------------------------------------------------");
httpget = new HttpGet("http://202.99.102.23/TJTAX_NET/NetLevy/NetQuery/TicketUse/edit.jsp");
response = httpClient.execute(httpget, localContext);
result=EntityUtils.toString(response.getEntity());
System.out.println(result);
System.out.println("--------------------------------------------------------------------------------------");
我怀疑httpclient无法完全模拟浏览器。可能有一些兼容性问题。
--------------------编程问答--------------------
这个是对方服务器报的异常。 --------------------编程问答-------------------- http://blog.csdn.net/jdgdf566/article/details/17039693
补充:Java , Web 开发