我正在构建一个Android应用程序,它使用httpclient发布和检索wordpress服务器的数据.
由于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);
这个例子(这里)
这个解决方案仍然没有结果
这是我的Android代码到目前为止发送http帖子数据
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);
我整天都经历过这一切,但没有结果.有人可以帮忙吗?