0
我正在使用Graph Story neo4j服務器,並使用我的android應用程序中的REST API。neo4j來自android應用程序的401狀態碼
我使用URL這樣https://uName:[email protected]:port
此相同的URL和HTTP參數和報頭我在鉻REST客戶端設置工作,但我得到的Neo4j 401個狀態錯誤,當我用我的Android應用程序。
從我的MainActivity調用此:
new RegisterRestTask().execute("https://GraphStoryUsername:[email protected]:7473/db/data/cypher");
這是我的AsyncTask代碼:
public class RegisterRestTask extends AsyncTask<String,Void,String> {
@Override
protected String doInBackground(String... urls) {
HttpClient httpClient=new DefaultHttpClient();
HttpPost httpPost=new HttpPost(urls[0]);
String json="{ \"query\":\"Match n return n\"} ";
try {
JSONObject postJsonObject=new JSONObject(json);
StringEntity jsonEntity=new StringEntity(postJsonObject.toString(),"UTF-8");
httpPost.setHeader("Accept", "application/json; charset=UTF-8");
httpPost.setHeader("Content-type", "application/json");
httpPost.setEntity(jsonEntity);
//httpPost.setHeader("User-Agent","Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.111 Safari/537.36");
HttpResponse httpResponse = httpClient.execute(httpPost);
Log.e("response",Integer.toString(httpResponse.getStatusLine().getStatusCode()));
}
catch (Exception e)
{
e.printStackTrace();
}
return null;
}
}
嗨,謝謝你的回覆。我已經添加了代碼 – 2015-02-24 01:37:15
請參閱此處將用戶名/密碼作爲附加驗證標頭傳遞:http://stackoverflow.com/questions/12443050/android-httpclient-json-post-with-basic-authentication – 2015-02-24 03:38:51