5
I am trying to send a token, through an Android application in the 'X-auth-token' header field. This request is sent to a PHP server, where I use Codeigniter.
Android
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(URL_PATH);
httpPost.setHeader("X-auth-token", token);
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("nome", this.nome_value));
UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(nameValuePairs);
httpPost.setEntity(urlEncodedFormEntity);
try {
HttpResponse httpResponse = httpClient.execute(httpPost);
//...
}
Server
...
$res = $CI->input->request_headers()['X-auth-token'];
...
Problem: $res is not set, as if the 'X-auth-token' field did not exist.
1 - How can I send the header field 'X-auth-token' on Android?
2 - I am using the 'X-auth-token' field because I read that it is safer than a normal post field, to send confidential data.
Is it possible for you to use a library? I pass a token but do not use the
HttpClient
. If it exists I can show you how I do in my case– Kayan Almeida