Android and HTTP request field X-auth-token

Asked

Viewed 331 times

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

1 answer

1

Good afternoon. Dude, I found 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 if you just change HTTP:Authorization and HTTP_AUTHORIZATION:%1, should work.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.