作者aadean (喝杯JAVA)
看板bioinfo_lab
标题Re: [讨论] 给阿pu看的 XD
时间Fri Jan 20 21:41:44 2006
※ 引述《agomi (莱姆酒)》之铭言:
: 在我们使用post方法的时候
: 因为网页会跟我们要资料 所以要回传资料给她们
: 在httpclient里面用的是NameValuePair这个方法
: 以我同学的mail server为例 : http://mail.formula7.idv.tw
: 我所准备的NameValuePair有下面这几个
: NameValuePair action = new NameValuePair("action", "/cgi-bin/openwebmail/openwebmail.pl");
: NameValuePair userid = new NameValuePair("loginname", "我同学的帐号名称");
: NameValuePair password = new NameValuePair("password", "我同学的密码");
: NameValuePair login = new NameValuePair("logindomain", "mail.formula7.idv.tw");
: 我跟同学讨论之後 他告诉我 我要注意每个具有<input>的标签
: ex. <Input type = "text" name="loginname" ... OOXX ... >
: 因为每个input都可能是网页要求的参数 如果网页没有要到参数 开网页就会失败
: 问题是检视原始码的时候 可能有10个input标签
: 但是我不知道网页其实需要几个输入的参数
: 像上面这四个NameValuePair好像也是试误法猜出来的
: 我如果只写前面三个好像也可以跑出一样的结果
: 不管怎样 我已经可以用PostMethod把这些名值对传入网页 顺利通过认证
: 而且我家远端桌面台大很慢 (web of knowledge要台大ip才能开)
: 所以我想先试试看对google作search动作
: 我的想法是google只有一个输入栏位
: 所以我只准备一个NameValuePair
: 写成 NameValuePair search = new NameValuePair( "hl", "Agomi" ) ;
: 表示我想在google上查询Agomi
: 但是传回的statuscode是501
Google是用get方式传资料
应该是用了post方式才会出现这样错误
只不过我试了一下用get方式传,似乎抓不到资料
: 内容是:
: 10.5.2 501 Not Implemented
: The server does not support the functionality required to fulfill the request.
: This is the appropriate response when the server does not recognize the request
: method and is not capable of supporting it for any resource.
: google的原始码中还有很多组input标签
: 但是我看不出我该怎麽选择
: 而且如果每次都要这样猜 好像很不合理 ?
: 如果有10个input标签
: 那可是有10!种组合
: 所以我这边的问题就是...
: 有没有更好的方法看出我们需要准备几组NameValuePair来喂给网页 ?
: 有没有办法得知网页需要几个input parameter ?
: 大家来讨论看看吧 :)
: 我想如果你还没看到这边 我上面写的东西也可以算是我前镇子的心得 :)
今天有一点点小小进展...可以抓到前十笔的snippet了
只是getPostMethod里的SID的值要先上网做查询动作检示原始码
看新的SID码是什麽,替换新的就可以抓到资料了...
还有一点就是网页不能关掉
里面还有一些额外程式码是自动抓SID的...
先用get抓到SID,再用post方式把SID传过去
不过没有成功...等我试好了再po上来了...
-----------------------------------------------------
package httpclient;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.methods.GetMethod;
import java.io.*;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class ISI {
public static void main(String[] args) {
ISI isi = new ISI();
HttpClient client = new HttpClient();
HttpMethod method = null;
/*String SIDHtmlContent = isi.getSIDHTMLContent(client,method);
Session session = new Session();
session.setCandidate(SIDHtmlContent);
session.setRegex("SID=.*&Fun");
String SID = session.getSID();
String finalSID = session.normalizeSID(SID);
*/
client.getHostConfiguration().setHost("xs17.isiknowledge.com",80,"http");
method = isi.getPostMethod("finalSID");
try {
client.executeMethod(method);
System.out.println(method.getResponseBodyAsString());
} catch (IOException ex) {
}
method.releaseConnection();
}
public String getSIDHTMLContent(HttpClient client,HttpMethod method)
{
String content = "";
method = new GetMethod("
http://portal.isiknowledge.com/portal.cgi");
try {
client.executeMethod(method);
System.out.println(method.getStatusLine());
content = method.getResponseBodyAsString();
} catch (IOException ex) {
}
finally {
//method.releaseConnection();
}
return content;
}
private HttpMethod getPostMethod(String strSID){
PostMethod post = new PostMethod("/CIW.cgi");
NameValuePair Form = new NameValuePair("Form","HomePage");
NameValuePair Func = new NameValuePair("Func","Search");
NameValuePair SID = new NameValuePair("SID","C2L9BKp683@poBieCPd");
NameValuePair topic = new NameValuePair("topic","nod2");
post.setRequestBody(new NameValuePair[] { Form,Func,SID,topic});
return post;
}
}
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.112.137.133
※ 编辑: aadean 来自: 140.112.137.133 (01/20 21:48)
1F:推 agomi:我昨天看你的jsp2.0技术手册上面有写到有个jsp指令可以抓到 01/21 10:23
2F:→ agomi:session id 而且自动加入网址之後回传出来 但不知道httpclie 01/21 10:23
3F:→ agomi:有没有类似的方法 01/21 10:24