I am using a Graph Story neo4j server and I am using the REST API from my android app.
I using the URL like this https://uName:pass@host:port
This same url and the http parameters and headers I set work in chrome Rest Client but I get a 401 status error from neo4j when I use my android app.
Calling this from my MainActivity:
new RegisterRestTask().execute("https://GraphStoryUsername:GraphStoryPassword@GraphStoryNeo4jInstanceURL:7473/db/data/cypher");
This is my AsyncTask Code:
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;
}
}