未导入jar文件
下面这个程序是网上的一段关于登陆人人网然后抓取相关信息的程序,但是未导入jar文件包,小弟刚刚学习java不久,望大神们能给写全import jar文件,我导入了一些,但是还是报错,希望各位大神帮忙看一下,看看是程序的问题还是jar文件不全的问题,这个程序对我很有用,大神们一定要帮帮小弟
public
class RenRen {
// The configuration items
private
static String userName = "YourMailinRenren";
private
static String password = "YourPassword";
private
static String redirectURL = "http://blog.renren.com/blog/304317577/449470467";
// Don't change the following URL
private
static String renRenLoginURL = "http://www.renren.com/PLogin.do";
// The HttpClient is used in one session
private HttpResponse response;
private DefaultHttpClient httpclient = new DefaultHttpClient();
private
boolean login() {
HttpPost httpost = new HttpPost(renRenLoginURL);
// All the parameters post to the web site
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
nvps.add(new BasicNameValuePair("origURL", redirectURL));
nvps.add(new BasicNameValuePair("domain", "renren.com"));
nvps.add(new BasicNameValuePair("isplogin", "true"));
nvps.add(new BasicNameValuePair("formName", ""));
nvps.add(new BasicNameValuePair("method", ""));
nvps.add(new BasicNameValuePair("submit", "登录"));
nvps.add(new BasicNameValuePair("email", userName));
nvps.add(new BasicNameValuePair("password", password));
try {
httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
response = httpclient.execute(httpost);
} catch (Exception e) {
e.printStackTrace();
return
false;
} finally {
httpost.abort();
}
return
true;
}
private String getRedirectLocation() {
Header locationHeader = response.getFirstHeader("Location");
if (locationHeader == null) {
return
null;
}
return locationHeader.getValue();
}
private String getText(String redirectLocation) {
HttpGet httpget = new HttpGet(redirectLocation);
// Create a response handler
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String responseBody = "";
try {
responseBody = httpclient.execute(httpget, responseHandler);
} catch (Exception e) {
e.printStackTrace();
responseBody = null;
} finally {
httpget.abort();
httpclient.getConnectionManager().shutdown();
}
return responseBody;
}
public
void printText() {
if (login()) {
String redirectLocation = getRedirectLocation();
if (redirectLocation != null) {
System.out.println(getText(redirectLocation));
}
}
}
public
static
void main(String[] args) {
RenRen renRen = new RenRen();
renRen.printText();
}
}
jar java
[解决办法]
你前面一定有:
import org.apache.commons.httpclient.Header或
import org.apache.commons.httpclient.*
改成:
import org.apache.http.Header
就行了,或者:
org.apache.http.Header locationHeader = response.getFirstHeader("Location");
[解决办法]
你前面一定有:
import org.apache.commons.httpclient.Header或
import org.apache.commons.httpclient.*
改成:
import org.apache.http.Header
就行了,或者:
org.apache.http.Header locationHeader = response.getFirstHeader("Location");
这是运行结果的一部分是红字为什么?
九月 06, 2013 9:51:18 上午 org.apache.http.client.protocol.ResponseProcessCookies processCookies
WARNING: Cookie rejected: "[version: 0][name: t][value: 08c932d7b8e9bed3b229e02850c648fc][domain: renren.com][path: /xtalk/][expiry: null]". Illegal path attribute "/xtalk/". Path of origin: "/PLogin.do"
还有进去后的内容为什么是html源文件,而不是页面显示的那种文本信息,小弟是想学这个方法,所以想先保证正确再学,希望大神帮忙解释一下