在 Http Header 中使用 Json 字符串 [英] Using Json string in the Http Header

查看:123
本文介绍了在 Http Header 中使用 Json 字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我在使用 http 标头时遇到了一些奇怪的问题(添加多个自定义http请求头之谜)为了避免当时的问题,我将字段放入json字符串并将该json字符串添加到头中,而不是将这些字段添加到单独的http头中.

Recently I run into some weird issue with http header usage ( Adding multiple custom http request headers mystery) To avoid the problem at that time, I have put the fields into json string and add that json string into header instead of adding those fields into separate http headers.

例如,代替

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

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

I have created a json string and add it to the single header

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

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

Since I am new to writing Rest and dealing with the Http stuff, I don't know if my usage is proper or not. I would appreciate some insight into this.

一些链接

http://lists.w3.org/档案/公共/ietf-http-wg/2011OctDec/0133.html

推荐答案

据我了解,在 header 选项中使用 json 字符串并不像使用 http DELETE for http GET 那样滥用使用,因此甚至有建议在 http 标头中使用 json.当然,仍然欢迎更深入的见解,并且仍有待给出公认的答案.

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.

这篇关于在 Http Header 中使用 Json 字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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