電子書籍の厳選無料作品が豊富!

MixiにログインするサンプルプログラムがあったのでEclipse上動かそうと思い
HttpClientのライブラリをダウンロードし実行しようとしたところ
PostMethod、GetMethodについて型に解決できませんと出ました。
ダウンロードしたファイルの中にあった全てのjar(以下の6個)にパスを通したのですが
まだ何かライブラリが足りないのでしょうか。
・commons-codec-1.4.jar
・commons-logging-1.1.1.jar
・httpclient-4.1.2.jar
・httpclient-cache-4.1.2.jar
・httpcore-4.1.2.jar
・hhtpmime-4.1.2.jar




import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import org.apache.http.HttpException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.params.CookiePolicy;
import org.apache.http.impl.client.DefaultHttpClient;


public class MixiLogin2 {

public static void main(String[] args) {
HttpClient client = new DefaultHttpClient();

String mixiLogin = "http://mixi.jp/login.pl";
String mixiTopPage = "http://mixi.jp/home.pl";
String encode = "EUC-JP";
String inputUserName = "email";
String inputPassword = "password";
String inputNextUrl = "next_url";
String userName = "xxxxx@xxxxx.com";
String password = "xxxx123456789";
String nextUrl = "/home.pl";

PostMethod postMethod = new PostMethod(mixiLogin);
postMethod.addParameter(inputUserName, userName);
postMethod.addParameter(inputPassword, password);
postMethod.addParameter(inputNextUrl, nextUrl);
postMethod.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);

try {
int statusCode = client.executeMethod(postMethod);
System.out.println(statusCode);

postMethod.releaseConnection();

if (statusCode == 200) {
GetMethod getMethod = new GetMethod(mixiTopPage);

statusCode = client.executeMethod(getMethod);
if (statusCode == 200) {
BufferedReader br = new BufferedReader(
new InputStreamReader(getMethod
.getResponseBodyAsStream(), encode));
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
}

getMethod.releaseConnection();
}
} catch (HttpException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}

A 回答 (1件)

GetMethodもPostMethodもimportされてないからでは。

    • good
    • 0
この回答へのお礼

インポートしようとしたところEclipse上でも
GetMethodとPostMethodだけインポートの候補が表示されませんでした。
commons-httpclient-3.1.jarを導入したところインポートできるようになり
解決できました。

お礼日時:2011/10/15 23:17

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!