大家好,小弟欲通过httpclient请求一个远程的dwr,我用工具fiddler(跟踪IE的工具)执行后,可以返回正常结果,请求如下(由于业务保密起见,url被我替换掉了,见谅):POST /test/dwr/exec/LoginService.getVaildCode.dwr HTTP/1.0
Accept: */*
Content-Type: text/plain
Referer: http://www.test.com/test/loginForm.jsp
Accept-Language: zh-cn
Connection: Keep-Alive
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; CIBA; .NET CLR 2.0.50727)
Host: www.test.com
Content-Length: 124
Pragma: no-cache
Cookie: __utma=43019386.104745520.1261384217.1261384217.1261385409.2; __utmb=43019386; __utmz=43019386.1261384217.1.1.utmccn=(direct)|utmcsr=(direct)|utmcmd=(none); __utmc=43019386; AMWEBJCT!%2Fportal!JSESSIONID=0000vp8J2WKmWHaiwYA6NzEIdg1:12i8cva0s; AMWEBJCT!%2Fportalframework!JSESSIONID=0000AnnN9kgzJPPSBfp_tgFs4Gk:12kqirar5
X-ProcessAndThread: iexplore.exe [3472; 1560]
X-Tickcount: 30238734callCount=1
c0-scriptName=LoginService
c0-methodName=getVaildCode
c0-id=5284_1261385571156
c0-param0=boolean:false
xml=true上面的信息是我从那个fiddler工具上复制过来的,它返回的结果是正常的,返回:var s0="5815";
然后我根据上面的信息,写了个请求,httpclient请求代码如下: HttpClient httpclient = new HttpClient();
PostMethod postMethod = new PostMethod("http://www.test.com//test/dwr/exec/LoginService.getVaildCode.dwr");
NameValuePair[] postData = new NameValuePair[5];
postData[0] = new NameValuePair("callCount", "1");
postData[1] = new NameValuePair("c0-scriptName", "LoginService");
postData[2] = new NameValuePair("c0-methodName", "getVaildCode");
postData[3] = new NameValuePair("c0-param0", "boolean:false");
postData[4] = new NameValuePair("xml", "true");
postMethod.addParameters(postData);
postMethod.getParams().setCookiePolicy(CookiePolicy.RFC_2109);
postMethod.setRequestHeader("Cookie", "__utmc=43019386; __utma=43019386.104745520.1261384217.1261384217.1261384217.1; __utmb=43019386; __utmz=43019386.1261384217.1.1.utmccn=(direct)|utmcsr=(direct)|utmcmd=(none); AMWEBJCT!%2Fportal!JSESSIONID=0000J0BkeQlVdsPD9haPJs_n7Hq:12i8cva0s; AMWEBJCT!%2Fportalframework!JSESSIONID=0000OkuGG5FGCjUho0TKKS-lkPl:12kqirar5"); httpclient.executeMethod(postMethod);但是结果返回:var s0=null; 请问我的java代码有问题吗,是不是我少向服务器端发送了某些数据了呢?谢谢,谢谢~~
注:服务器端代码我看不到。
Accept: */*
Content-Type: text/plain
Referer: http://www.test.com/test/loginForm.jsp
Accept-Language: zh-cn
Connection: Keep-Alive
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; CIBA; .NET CLR 2.0.50727)
Host: www.test.com
Content-Length: 124
Pragma: no-cache
Cookie: __utma=43019386.104745520.1261384217.1261384217.1261385409.2; __utmb=43019386; __utmz=43019386.1261384217.1.1.utmccn=(direct)|utmcsr=(direct)|utmcmd=(none); __utmc=43019386; AMWEBJCT!%2Fportal!JSESSIONID=0000vp8J2WKmWHaiwYA6NzEIdg1:12i8cva0s; AMWEBJCT!%2Fportalframework!JSESSIONID=0000AnnN9kgzJPPSBfp_tgFs4Gk:12kqirar5
X-ProcessAndThread: iexplore.exe [3472; 1560]
X-Tickcount: 30238734callCount=1
c0-scriptName=LoginService
c0-methodName=getVaildCode
c0-id=5284_1261385571156
c0-param0=boolean:false
xml=true上面的信息是我从那个fiddler工具上复制过来的,它返回的结果是正常的,返回:var s0="5815";
然后我根据上面的信息,写了个请求,httpclient请求代码如下: HttpClient httpclient = new HttpClient();
PostMethod postMethod = new PostMethod("http://www.test.com//test/dwr/exec/LoginService.getVaildCode.dwr");
NameValuePair[] postData = new NameValuePair[5];
postData[0] = new NameValuePair("callCount", "1");
postData[1] = new NameValuePair("c0-scriptName", "LoginService");
postData[2] = new NameValuePair("c0-methodName", "getVaildCode");
postData[3] = new NameValuePair("c0-param0", "boolean:false");
postData[4] = new NameValuePair("xml", "true");
postMethod.addParameters(postData);
postMethod.getParams().setCookiePolicy(CookiePolicy.RFC_2109);
postMethod.setRequestHeader("Cookie", "__utmc=43019386; __utma=43019386.104745520.1261384217.1261384217.1261384217.1; __utmb=43019386; __utmz=43019386.1261384217.1.1.utmccn=(direct)|utmcsr=(direct)|utmcmd=(none); AMWEBJCT!%2Fportal!JSESSIONID=0000J0BkeQlVdsPD9haPJs_n7Hq:12i8cva0s; AMWEBJCT!%2Fportalframework!JSESSIONID=0000OkuGG5FGCjUho0TKKS-lkPl:12kqirar5"); httpclient.executeMethod(postMethod);但是结果返回:var s0=null; 请问我的java代码有问题吗,是不是我少向服务器端发送了某些数据了呢?谢谢,谢谢~~
注:服务器端代码我看不到。
解决方案 »
- jstl
- 使用MyEclipse,Tomcat6.0 ,struts2做jsp登录页面,出错:Unable to load configuration. - action
- Android短信功能实现源码
- HttpURLConnection
- 关于orcale数据库索引的问题
- 我分别试过getString(),getInt(),getLong(),都不行,getObject()取出来的东西,直接输入是:null。用getBytes()取出来长度为15,少一位
- 请问如何在网页播放器播放中文名的文件?
- 可否在javascript函数里调用jsp代码啊?
- Hibernate4.3.1 创建session工厂的问题
- Servlet 页面跳转后,接收不到登陆信息
- 涉及过和通联打交道的支付异或对账流程的大侠们请举手!!
- 很奇怪的问题
callCount=1
c0-scriptName=LoginService
c0-methodName=getVaildCode
c0-id=5284_1261385571156
c0-param0=boolean:false
xml=true