Today: Yesterday: Total: Online:
カテゴリー
その他
  • RSS1.0
  • RSS2.0
  • atom0.3
  • valid XHTML1.0
  • valid CSS2
  • Credit
RSSリーダーで購読する | この日記のはてなブックマーク数 | プロフィール
コメントが一番多い記事(233コメント):人の心理の裏をかくホームページ集客術:リピータになってもらうためには
ツイートが一番多い記事(94ツイート):ちょっと待て!twitterやfacebookに子供の写真を掲載する親達への警告
いいねが一番多い記事(574いいね):facebookスパムに要注意。なりすましの見分け方とアカウント乗っ取りの手口(2013年度版)

[ カテゴリー » JAVA » httpUnit ]

カテゴリー » JAVA » httpUnit March 11, 2008

HttpUnitでユーザーエージェントの偽装 ID:1205214363


ClientProperties.getDefaultProperties()を使う。


こんな感じ。
ClientProperties.getDefaultProperties().setUserAgent("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");



requestをやる前にエージェントを偽装しないとうまくセットされないっぽい。
1 / 2| 次のページ »

— posted by midilin @ 02:46PM

カテゴリー » JAVA » httpUnit March 10, 2008

リンクやForm中のButtonをクリックするときのレスポンス取得方法 ID:1205142036


リンクやForm中のButtonをクリックする操作をプログラムから実行する場合、WebResponseが戻されないのでWebConversation.getCurrentPage()で取得する必要がある。



WebLink link = res.getLinkWith( "response" );
link.click();
WebResponse res = wc.getCurrentPage();


http://d.hatena.ne.jp/ksaito11/20060530
1 / 2| 次のページ »

— posted by midilin @ 06:40PM

カテゴリー » JAVA » httpUnit March 10, 2008

httpunit の Cookie(クッキー) 拒否 ID:1205140458


リクエストしたパスとそこで発行された Cookie の path 属性が異なる場合、

デフォルトでは Cookie を受け取らない。

例えば、

/login

にアクセスした際に、

path=/admin

の Cookie を発行しても httpunit は受け取らない。



受け取るには、CookieProperties.setPathMatchingStrict(false) を呼び出す必要がある。


http://d.hatena.ne.jp/dragon3/20050215/1108437622


また、ネットのどこにも情報がないが、
CookieProperties.setDomainMatchingStrict
というのがあり、こちらはドメイン間が違うクッキーを引き渡すときに
指定が必要のようである。
(ドメイン間のクッキーの引渡しが失敗したところを
 CookieProperties.setDomainMatchingStrict(false);
 にしたらうまくいった)
1 / 2| 次のページ »

— posted by midilin @ 06:14PM

カテゴリー » JAVA » httpUnit March 03, 2008

HttpUnitでhidden項目に値を設定する方法 ID:1204520219


webForm.setParameter("title", "123");
では、駄目。


form.getScriptableObject().setParameterValue("title", "741");
のようにセットする


http://hidamarinonaka.jugem.cc/?eid=44
1 / 2| 次のページ »

— posted by midilin @ 01:56PM

カテゴリー » JAVA » httpUnit March 03, 2008

httpUnitでプルダウン(option)の値がとれない ID:1204514518


いろいろデバッグしてみた結果、
html属性がついていると駄目っぽい。


<html xmlns="http://www.w3.org/1999/xhtml">
 


となっていると、プルダウンが取得できないが


<html">

 

にするとプルダウンの値がとれた
1 / 2| 次のページ »

— posted by midilin @ 12:21PM

カテゴリー » JAVA » httpUnit March 03, 2008

httpUnitのSELECT/OPTION 要素の取得とセット ID:1204508943


// 最初のフォームを取得
WebForm[] forms = response.getForms();
WebForm form = forms[0];

// フォーム中の SELECT/OPTION 要素の値を取得
String[] values = form.getOptionValues("item_name");

// フォームの値をセット
form.setParameter("cust_id",   Integer.toString(customerId));
form.setParameter("item_name", values[random(values.length)]);
form.setParameter("qty",       Integer.toString(1));


http://www.nminoru.jp/~nminoru/diary/2005/06.html
1 / 2| 次のページ »

— posted by midilin @ 10:49AM

カテゴリー » JAVA » httpUnit February 29, 2008

httpunitでJavascript無効にする ID:1204279339


HttpUnitOptions.setScriptingEnabled(false);
で、無効になる。


JavascriptのExceptionが出る場合は、
無効にすると解決することがある。


http://hidamarinonaka.jugem.cc/?eid=45
1 / 2| 次のページ »

— posted by midilin @ 07:02PM

カテゴリー » JAVA » httpUnit February 29, 2008

httpunitのフォーム送信 ID:1204277303


import com.meterware.httpunit.GetMethodWebRequest;
import com.meterware.httpunit.SubmitButton;
import com.meterware.httpunit.WebConversation;
import com.meterware.httpunit.WebForm;
import com.meterware.httpunit.WebRequest;
import com.meterware.httpunit.WebResponse;

public class ButtonClick {
    public static void main(String[] args) throws Exception{
        String url = "http://www.google.co.jp/";

        WebConversation wc = new WebConversation();
        WebRequest request = new GetMethodWebRequest(url);
        WebResponse response = wc.getResponse(request);
        System.out.println(response.getURL().toString());

        WebForm form = response.getFormWithName("f");
        form.setParameter("q", "yahoo");
        form.setParameter("lr", "lang_ja");
        SubmitButton button = form.getSubmitButton("btnG");
        response = form.submit(button);
        System.out.println(response.getURL().toString());
    }
}



http://blog.yuki.sub.jp/?eid=317656
1 / 2| 次のページ »

— posted by midilin @ 06:28PM