最近,我遇到了一些关于http头使用的奇怪问题(Adding multiple custom http request headers mystery),为了避免当时的问题,我将字段放入json字符串中,并将该json字符串添加到头中,而不是将这些字段添加到单独的http头中.

For example, instead of

request.addHeader("UserName", mUserName);
request.addHeader("AuthToken", mAuthorizationToken);
request.addHeader("clientId","android_client");

我创建了一个json字符串,并将其添加到单个头中

String jsonStr="{\"UserName\":\"myname\",\"AuthToken\":\"123456\",\"clientId\":\"android_client\"}";
request.addHeader("JSonStr",jsonStr);

由于我对编写Rest和处理Http内容还不熟悉,我不知道我的用法是否正确.我希望能对此有所了解.

Some links

http://lists.w3.org/Archives/Public/ietf-http-wg/2011OctDec/0133.html

推荐答案

From what I understand using a json string in the header option is not as much of an abuse of usage as using http DELETE for http GET, thus there has even been proposal to use json in http header. Of course more thorough insights are still welcome and the accepted answer is still to be given.

Json相关问答推荐

无法根据vega规范中的条件设置文本 colored颜色

如何在VegaLite中应用Times New Roman,CaliBiri字体

如何判断响应数组是否存在以及S是否有其他内容...?

集成wix.comstore API|变音符号问题

ETCD 导出为 json 并从 base64 解码所有键/值到人类可读

如何在不使用 Newtonsoft.JSON 的情况下序列化/反序列化

从 JSON 响应中获取最新版本发布字段

如何在 powerapps 中将详细信息表单转换为 json?

传统编程语言等价于动态 SQL

Servicestack 返回数组而不是带有数组的对象

boost::json::value 的大括号初始化将其从对象转换为数组

在 Perl Mojolicious 中呈现 JSON 时防止转义字符

直接从 Java 中的模型类创建 JSON 对象

Jackson 动态属性名称

没有默认构造函数的杰克逊第 3 方类

jQuery JSON 响应总是触发 ParseError

在 Webpack 中加载静态 JSON 文件

如何使用 Javascript 将数据写入 JSON 文件

JSON - 是否有任何 XML CDATA 类似功能?

通过url获取json数据并在python中使用(simplejson)