我正在構建一個android應用程序,它使用httpclient將數據發佈並檢索到wordpress服務器。Android httpclient cookie拒絕非法路徑屬性
由於Cookie中的路徑無效,我無法發送發佈數據。這裏是我檢索的日誌:
Cookie rejected: "BasicClientCookie[version=0,name=wordpress_654732f696815924ebd07fb96f161421,domain=[my-domain],path=/wp-content/plugins,expiry=Thu Feb 13 07:53:10 GMT+07:00 2014]".Illegal path attribute "/wp-content/plugins". Path of origin: "/api/auth/generate_auth_cookie/"
Cookie rejected: "BasicClientCookie[version=0,name=wordpress_654732f696815924ebd07fb96f161421,domain=[my-domain],path=/wp-admin,expiry=Thu Feb 13 07:53:10 GMT+07:00 2014]". Illegal path attribute "/wp-admin". Path of origin: "/api/auth/generate_auth_cookie/"
我搜索了論壇,並嘗試給出的解決方案,但它仍然拒絕從應用程序的cookie。幾種解決方案我已經試過有:
設置cookie的政策
httpclient.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BROWSER_COMPATIBILITY);
這個例子(here)
This解決方案,還是沒有結果
這裏的我的android代碼到目前爲止發送http post d ata
CookieStore cookieStore = new BasicCookieStore();
httpclient.setCookieStore(cookieStore);
CookieSpecFactory csf = new CookieSpecFactory() {
@Override
public CookieSpec newInstance(HttpParams httpParams) {
return new BrowserCompatSpec(){
@Override
public void validate (Cookie cookie, CookieOrigin origin)
throws MalformedCookieException{
Log.d("COOKIE", "force validate cookie path info: " + cookie.getPath() +
", origin: " + origin.getPath());
}
};
}
};
httpclient.getCookieSpecs().register("custom_validate", csf);
httpclient.getParams().setParameter(ClientPNames.COOKIE_POLICY, "custom_validate");
HttpPost httppost = new HttpPost(url);
if(postData != null){
httppost.setEntity(postData);
}
HttpResponse response = httpclient.execute(httppost);
我已經經歷了這一整天,但沒有結果。 任何人都可以幫忙嗎?
有關發送數據作爲鏈接參數是什麼? – Rokas
我試過上面的代碼對我有用,我打電話給asyntask中的httpclient代碼並點擊-http://blog.com/wp-login.php?與我的用戶名和pwd的網址,並顯示webview中的響應它顯示我登錄的頁面。如果沒有CookieSpecFactory,則會顯示Cookie曲目警告並繼續顯示登錄頁面。 – Neha
順便說一句,什麼網址打什麼postdata? – Neha