添加多个自定义http请求标头之谜 [英] Adding multiple custom http request headers mystery

查看:182
本文介绍了添加多个自定义http请求标头之谜的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HttpGet request = new HttpGet("https://192.168.1.140:8732/...);

我想知道为什么我只能成功发送自定义标题:UserName和AuthToken如果我执行以下操作:

I wonder why I can only send successfully for custom headers : UserName and AuthToken if I do the following:

    request.setHeader("User-Agent", "android_client");
    request.setHeader("Host", "192.168.1.140:8732");
    request.addHeader("UserName", mUserName);
    request.addHeader("AuthToken", mAuthorizationToken);

为什么这段代码不仅仅发送UserName而只发送AuthToken?当两条底线相反时。

Why is that this code NOT sending the UserName but AuthToken only? When the two bottom lines are reversed.

    request.setHeader("User-Agent", "android_client");
    request.setHeader("Host", "192.168.1.140:8732");
    request.addHeader("AuthToken", mAuthorizationToken);
    request.addHeader("UserName", mUserName);

为什么这段代码失败了400错误代码,当我没有特定主机时无效的主机名

Why is this code failing with 400 error code, invalid hostname when I don't specific the host

//  request.setHeader("User-Agent", "android_client");
//  request.setHeader("Host", "192.168.1.140:8732");
    request.addHeader("UserName", mUserName);
    request.addHeader("AuthToken", mAuthorizationToken);

如果我不需要发送UserName和AuthToken,我真的不需要设置主机和它的工作正常,代码注释如下:

If I don't need to send the UserName and AuthToken, I don't really need to set the Host and it works just fine with the code commented out like following

//  request.setHeader("User-Agent", "android_client");
//  request.setHeader("Host", "192.168.1.140:8732");

虽然我不认为它是相关的,但我想披露我正在使用自我这个博客。期待我可怜的http灵魂的神圣启示......

Though I don't think that it is related, I want to disclose that I am using self-signed certificate for these http call from android following this blog. Looking forward to the divine revelation for my poor http soul ...

推荐答案

这是一个侥幸。我再也无法重现了。我一直在使用工作解决方案,并在一段时间内处理不同的项目。我在 oleg 建议: //stackoverflow.com/questions/3246792/how-to-enable-logging-for-apache-commons-httpclient-on-android\">如何在Android上启用apache commons HttpClient的日志记录我无法重现问题了。伐木的力量吓跑了这个问题。如果问题再次发生并且如果我找出原因,将更新。

It is a fluke. I couldn't reproduce it anymore. I have been working with the working solution and left it for a while working on different project. I come back and take a look with wire /context logging at oleg suggestion with the help of How to enable logging for apache commons HttpClient on Android I couldn't reproduce the problem anymore. The power of the logging has scared the problem away. Will update if the problem occurs again and if I find out the cause.

这篇关于添加多个自定义http请求标头之谜的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆