import org.apache.commons.httpclient.Cookie;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpMethod;
public class TestOfPost {
private static final String LOGON_SITE = "222.195.226.80";
private static final int LOGON_PORT = 8080;
private static final String CONTENT_CHARSET = "GBK";
public static void main(String[] args) throws Exception{
HttpClient client = new HttpClient();
NameValuePair[] bodyData = {
new NameValuePair("E", "%28Keyword_C%3D%28%BB%FA%C6%F7%D1%A7%CF%B0%29%2BTitle_C%3D%28%BB%FA%C6%F7%D1%A7%CF%B0%29%29"),
new NameValuePair("S", "1"),
new NameValuePair("N","20"),
new NameValuePair("C","0"),
new NameValuePair("H","%CC%E2%C3%FB%BB%F2%B9%D8%BC%FC%B4%CA%3D%BB%FA%C6%F7%D1%A7%CF%B0*%C4%EA%3D1989-2009"),
new NameValuePair("M",""),
new NameValuePair("KM",""),
new NameValuePair("P","1"),
new NameValuePair("CSID","%7B7C68141A-0DA1-40A4-8027-8C96AE5A2C5F%7D")
};
client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, CONTENT_CHARSET);
client.getHostConfiguration().setHost(LOGON_SITE, LOGON_PORT);
PostMethod pmlogin = new PostMethod("/loginn_ybjs.asp");
pmlogin.addRequestHeader("User-Agent","Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; QQDownload 584; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)");
client.executeMethod(pmlogin);
Cookie[] cookiess = client.getState().getCookies();
client.getState().addCookies(cookiess);
System.out.println ("***************************************登录Response*****************************************");
System.out.println (pmlogin.getResponseBodyAsString());
PostMethod pml = new PostMethod("/CSTJ/Sear.dll?SearchZk");
pml.setRequestBody(bodyData);
pml.addRequestHeader("Accept","application/x-shockwave-flash, image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/QVOD, application/QVOD, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, */*");
pml.addRequestHeader("Referer","http://222.195.226.80:8080/loginn_ybjs.asp");
pml.addRequestHeader("Accept-Language","zh-cn");
pml.addRequestHeader("Content-Type","application/x-www-form-urlencoded");
pml.addRequestHeader("Accept-Encoding","gzip, deflate");
pml.addRequestHeader("User-Agent","Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; QQDownload 584; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)");
//pml.addRequestHeader("url", "/CSTJ/Sear.dll?SearchZK");
pml.addRequestHeader("Host","222.195.226.80:8080");
pml.addRequestHeader("Content-Length","250");
pml.addRequestHeader("Connection","Keep-Alive");
pml.addRequestHeader("Pragma","no-cache");
client.executeMethod(pml);
System.out.println ("***************************************查询Post-response*****************************************");
System.out.println (pml.getResponseBodyAsString());
pml.releaseConnection();
}
}
输出结果为:
[code=#]--------------------Configuration: <Default>--------------------
***************************************登录Response*****************************************
<html>
<head>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title></title>
</head>
<Form Name="SearchForm" Action="../CSTJ/Sear.dll?SearchZK" Method="Post" target="_self">
<input type="hidden" name="E" value="">
<input type="hidden" name="S" value="">
<input type="hidden" name="N" value="">
<input type="hidden" name="P" value="">
<input type="hidden" name="C" value="">
<input type="hidden" name="H" value="">
<input type="hidden" name="M" value="">
<input type="hidden" name="KM" value="">
<input type="hidden" name="CSID" value="{1959D47E-CCAC-4C2B-A72B-FDD83709E948}">
</Form>
<script for="window" event="onload" Language="VbScript">
SearchForm.submit
</script>
</head>
</html>
***************************************查询Post-response*****************************************
2009-10-4 13:01:29 org.apache.commons.httpclient.HttpMethodBase getResponseBody
警告: Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.
<BODY><H1>无效请求</H1><P>客户端发出一个服务器无法处理的请求.<br>请求: SearchZk
</body></html>
Process completed.[/code]
10 个解决方案
#1
提交查询的时候抓取到的HTTP post明文:
POST /CSTJ/Sear.dll?SearchZK HTTP/1.1
Accept: application/x-shockwave-flash, image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/QVOD, application/QVOD, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, */*
Referer: http://222.195.226.80:8080/CSTJ/Sear.dll?SearchZK
Accept-Language: zh-cn
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
User-Agent:
Host: 222.195.226.80:8080
Content-Length: 257
Connection: Keep-Alive
Pragma: no-cache
Cookie: WebSite=YW=0; CSID=%7BE07B6509%2DC6FE%2D4AE1%2DBC6B%2D180390B72979%7D222%2E195%2E151%2E139; VIPCSID=%7BE07B6509%2DC6FE%2D4AE1%2DBC6B%2D180390B72979%7D; User=YR=1989%2C2018&UN=1&UR=ZZ&Alllist=1&Name=%D6%D0%B9%FA%BA%A3%D1%F3%B4%F3%D1%A7&YWBrowse=0&UserID=1; ASPSESSIONIDSQACCABD=GEEPFJMAHJGOLBCOHBANPCOF
E=%28%28Keyword_C%3D%28%BB%FA%C6%F7%D1%A7%CF%B0%29%2BTitle_C%3D%28%BB%FA%C6%F7%D1%A7%CF%B0%29%29%29&S=1&N=50&P=1&C=0&H=%28%CC%E2%C3%FB%BB%F2%B9%D8%BC%FC%B4%CA%3D%BB%FA%C6%F7%D1%A7%CF%B0%29*1989-2009&M=&KM=&GX=&CSID=%7BE07B6509-C6FE-4AE1-BC6B-180390B72979%7D
请问,在使用httpclient post数据的时候,红色部分怎么使用?
我所使用的方法是否正确?
请各位大侠帮忙。
#2
/CSTJ/Sear.dll?SearchZK
这里为红色部分
这里为红色部分
#3
POST /CSTJ/Sear.dll?SearchZK HTTP/1.1
Accept: application/x-shockwave-flash, image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/QVOD, application/QVOD, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, */*
Referer: http://222.195.226.80:8080/CSTJ/Sear.dll?SearchZK
Accept-Language: zh-cn
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; QQDownload 584; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; 360SE)
Host: 222.195.226.80:8080
Content-Length: 257
Connection: Keep-Alive
Pragma: no-cache
Cookie: WebSite=YW=0; CSID=%7BDE95F8B3%2DE0CE%2D4BE6%2D8DEE%2DBBE73026298F%7D222%2E195%2E151%2E139; VIPCSID=%7BDE95F8B3%2DE0CE%2D4BE6%2D8DEE%2DBBE73026298F%7D; User=YR=1989%2C2018&UN=1&UR=ZZ&Alllist=1&Name=%D6%D0%B9%FA%BA%A3%D1%F3%B4%F3%D1%A7&YWBrowse=0&UserID=1; ASPSESSIONIDQQCCDCBC=BBKLJFLDCMCGOMPGBPJDNNAC
E=%28%28Keyword_C%3D%28%BB%FA%C6%F7%D1%A7%CF%B0%29%2BTitle_C%3D%28%BB%FA%C6%F7%D1%A7%CF%B0%29%29%29&S=1&N=20&P=1&C=0&H=%28%CC%E2%C3%FB%BB%F2%B9%D8%BC%FC%B4%CA%3D%BB%FA%C6%F7%D1%A7%CF%B0%29*1989-2009&M=&KM=&GX=&CSID=%7BDE95F8B3-E0CE-4BE6-8DEE-BBE73026298F%7D
请问有人能使用httpclient实现上面代码的post请求吗?
不胜感激
#4
post get 都可以把,楼主。。。
#5
***************************************查询Post-response*****************************************
2009-10-4 13:01:29 org.apache.commons.httpclient.HttpMethodBase getResponseBody
警告: Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.
<BODY> <H1>无效请求 </H1> <P>客户端发出一个服务器无法处理的请求. <br>请求: SearchZk
</body> </html>
但是为什么会有这个结果呢?不懂了
2009-10-4 13:01:29 org.apache.commons.httpclient.HttpMethodBase getResponseBody
警告: Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.
<BODY> <H1>无效请求 </H1> <P>客户端发出一个服务器无法处理的请求. <br>请求: SearchZk
</body> </html>
但是为什么会有这个结果呢?不懂了
#6
请问:
使用HTTPCLIENT POST,数据部分的content-lenght怎么计算?
使用HTTPCLIENT POST,数据部分的content-lenght怎么计算?
#7
人呢!
高手呢?
管理员呢?
版主呢?
???????????????????????????????????????????????????????????????????????????????????????????????????
高手呢?
管理员呢?
版主呢?
???????????????????????????????????????????????????????????????????????????????????????????????????
#8
谢谢~!真的好有用哦
#9
期待高手,帮顶
#10
高手呢?
人呢?
人呢?
#1
提交查询的时候抓取到的HTTP post明文:
POST /CSTJ/Sear.dll?SearchZK HTTP/1.1
Accept: application/x-shockwave-flash, image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/QVOD, application/QVOD, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, */*
Referer: http://222.195.226.80:8080/CSTJ/Sear.dll?SearchZK
Accept-Language: zh-cn
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
User-Agent:
Host: 222.195.226.80:8080
Content-Length: 257
Connection: Keep-Alive
Pragma: no-cache
Cookie: WebSite=YW=0; CSID=%7BE07B6509%2DC6FE%2D4AE1%2DBC6B%2D180390B72979%7D222%2E195%2E151%2E139; VIPCSID=%7BE07B6509%2DC6FE%2D4AE1%2DBC6B%2D180390B72979%7D; User=YR=1989%2C2018&UN=1&UR=ZZ&Alllist=1&Name=%D6%D0%B9%FA%BA%A3%D1%F3%B4%F3%D1%A7&YWBrowse=0&UserID=1; ASPSESSIONIDSQACCABD=GEEPFJMAHJGOLBCOHBANPCOF
E=%28%28Keyword_C%3D%28%BB%FA%C6%F7%D1%A7%CF%B0%29%2BTitle_C%3D%28%BB%FA%C6%F7%D1%A7%CF%B0%29%29%29&S=1&N=50&P=1&C=0&H=%28%CC%E2%C3%FB%BB%F2%B9%D8%BC%FC%B4%CA%3D%BB%FA%C6%F7%D1%A7%CF%B0%29*1989-2009&M=&KM=&GX=&CSID=%7BE07B6509-C6FE-4AE1-BC6B-180390B72979%7D
请问,在使用httpclient post数据的时候,红色部分怎么使用?
我所使用的方法是否正确?
请各位大侠帮忙。
#2
/CSTJ/Sear.dll?SearchZK
这里为红色部分
这里为红色部分
#3
POST /CSTJ/Sear.dll?SearchZK HTTP/1.1
Accept: application/x-shockwave-flash, image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/QVOD, application/QVOD, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, */*
Referer: http://222.195.226.80:8080/CSTJ/Sear.dll?SearchZK
Accept-Language: zh-cn
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; QQDownload 584; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; 360SE)
Host: 222.195.226.80:8080
Content-Length: 257
Connection: Keep-Alive
Pragma: no-cache
Cookie: WebSite=YW=0; CSID=%7BDE95F8B3%2DE0CE%2D4BE6%2D8DEE%2DBBE73026298F%7D222%2E195%2E151%2E139; VIPCSID=%7BDE95F8B3%2DE0CE%2D4BE6%2D8DEE%2DBBE73026298F%7D; User=YR=1989%2C2018&UN=1&UR=ZZ&Alllist=1&Name=%D6%D0%B9%FA%BA%A3%D1%F3%B4%F3%D1%A7&YWBrowse=0&UserID=1; ASPSESSIONIDQQCCDCBC=BBKLJFLDCMCGOMPGBPJDNNAC
E=%28%28Keyword_C%3D%28%BB%FA%C6%F7%D1%A7%CF%B0%29%2BTitle_C%3D%28%BB%FA%C6%F7%D1%A7%CF%B0%29%29%29&S=1&N=20&P=1&C=0&H=%28%CC%E2%C3%FB%BB%F2%B9%D8%BC%FC%B4%CA%3D%BB%FA%C6%F7%D1%A7%CF%B0%29*1989-2009&M=&KM=&GX=&CSID=%7BDE95F8B3-E0CE-4BE6-8DEE-BBE73026298F%7D
请问有人能使用httpclient实现上面代码的post请求吗?
不胜感激
#4
post get 都可以把,楼主。。。
#5
***************************************查询Post-response*****************************************
2009-10-4 13:01:29 org.apache.commons.httpclient.HttpMethodBase getResponseBody
警告: Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.
<BODY> <H1>无效请求 </H1> <P>客户端发出一个服务器无法处理的请求. <br>请求: SearchZk
</body> </html>
但是为什么会有这个结果呢?不懂了
2009-10-4 13:01:29 org.apache.commons.httpclient.HttpMethodBase getResponseBody
警告: Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.
<BODY> <H1>无效请求 </H1> <P>客户端发出一个服务器无法处理的请求. <br>请求: SearchZk
</body> </html>
但是为什么会有这个结果呢?不懂了
#6
请问:
使用HTTPCLIENT POST,数据部分的content-lenght怎么计算?
使用HTTPCLIENT POST,数据部分的content-lenght怎么计算?
#7
人呢!
高手呢?
管理员呢?
版主呢?
???????????????????????????????????????????????????????????????????????????????????????????????????
高手呢?
管理员呢?
版主呢?
???????????????????????????????????????????????????????????????????????????????????????????????????
#8
谢谢~!真的好有用哦
#9
期待高手,帮顶
#10
高手呢?
人呢?
人呢?