Android and HTTP request field X-auth-token

4

I'm trying to send a token through an Android application in the 'X-auth-token' field of the header. This request is sent to a PHP server, in which 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 'X-auth-token' header field on Android?

2 - I am using the 'X-auth-token' field because I have read that it is more secure than a normal post field, to send confidential data.     

asked by anonymous 19.05.2015 / 21:47

1 answer

0

Good afternoon. Dude, I encountered the same problem with Authorization. I made a rule to rewrite it in .htaccess as follows:

RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]

I think that if you just change HTTP:Authorization and HTTP_AUTHORIZATION:%1 , it should work.

    
08.03.2016 / 18:31