I am having trouble getting the Apache HttpClient to correctly send an HttpPost Header.
I have no problems sending name value pairs and whatnot, but whenever I set or add a POST Header, it disappears when the request is made.
I have tried both setHeader and addHeader, as well as trying both at once.
Here is my code:
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("https://posttestserver.com/post.php");
httppost.setHeader("Authorization: Bearer", accessToken);
httppost.addHeader("Authorization: Bearer", accessToken);
Log.d("DEBUG", "HEADERS: " + httppost.getFirstHeader("Authorization: Bearer"));
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String responseBody = httpclient.execute(httppost, responseHandler);
Log.d("DEBUG", "RESPONSE: " + responseBody);
Additionally, the debug statement before the request is executed prints out the correct header, so I know it is being added, then just dropped later.
Any help would be much appreciated!
EDIT: This is all running inside of an AsyncTask if that matters. I don’t think it does since there is a NetworkOnMainThread exception thrown otherwise but I thought it might be worth mentioning.
Try to connect the service that tells your HTTP headers and capture (just print plain HTML) the output. At least you will know if your headers are really lost on the way or maybe something else.