以前我在Android to Drupal cookie transfer問了一個關於從我的Android應用程序發回cookies到我的Drupal網站的問題,我得到了一個很好的答案。整個想法是啓用持續的客戶端 - 服務器交互。Android to Drupal cookie轉移Q2
我按照指示調整了代碼,但仍然無法正常工作。我的代碼調整低於:
protected Void doInBackground(Void... params) {
// TODO Auto-generated method stub
HttpResponse response;
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://testsite.com/testpoint/node/");
BasicHttpContext basicContext = new BasicHttpContext();
org.apache.http.client.CookieStore cookiestore = new BasicCookieStore();
basicContext.setAttribute(ClientContext.COOKIE_STORE, cookiestore);
basicContext.setAttribute(USERPREFERENCES.getString(COOKIE_NAME, ""), USERPREFERENCES.getString(COOKIE_VALUE, ""));
//USERPREFERENCES.getString(CO0OKIE_NAME, ""), USERPREFERENCES.getString(COOKIE_VALUE, "")
// TODO Auto-generated method stub
try{
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("node[title]", "sample node from app"));
nameValuePairs.add(new BasicNameValuePair("node[type]", "story"));
nameValuePairs.add(new BasicNameValuePair("node[body]", "sample app node body content"));
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
//Execute HTTP post request
//HttpResponse
response = httpClient.execute(httpPost, basicContext);
Log.i("SEEMS TO WORK", response.toString());
Log.v("CODE", httpPost.getRequestLine().toString() + " - " + response.toString());
}catch(Exception e){
Log.e("HTTP-ERROR: node creation", e.toString());
}
return null;
}
@Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
//Toast.makeText(getApplicationContext(), "Create Node thread returning!", Toast.LENGTH_LONG).show();
Toast.makeText(getApplicationContext(), "Testing header: Cookie: " + USERPREFERENCES.getString(COOKIE_NAME, "") +","+ USERPREFERENCES.getString(COOKIE_VALUE, ""), Toast.LENGTH_LONG).show();
}
}
基本上,我的cookie的名稱和值都存儲在我的共享偏好USERPREFERENCES.getString(COOKIE_NAME, 「」)和USERPREFERENCES.getString(COOKIE_VALUE, 「」)。 我正在嘗試發回這些信息,以便當此函數執行併成功在我的Drupal站點上創建新的故事節點時,作者將被識別爲從Android應用程序註冊並登錄的用戶。
目前,該節點已創建,但用戶是「匿名」的。因此,我需要發回Drupal的用戶cookie信息。
任何人都可以請幫助我嗎?
謝謝你的工具建議。我馬上開始。 – sisko 2011-06-05 21:17:16
np。正確設置反向代理可能會有一些竅門。如果您遇到麻煩,請告訴我,我可以嘗試將您指向正確的方向。 – walta 2011-06-05 23:16:23
嗨沃爾塔,這聽起來很瘋狂,但charlesproxy網站似乎倒閉了。我設法在家裏在Linux上下載它,但在我的Windows機器上工作,我可以花更多的時間玩它,該網站拒絕加載... – sisko 2011-06-07 08:17:43