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

查看:1864
本文介绍了在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/Archives/Public/ietf- http-wg / 2011OctDec / 0133.html

推荐答案

据我所知,在标题选项中使用json字符串对于http GET使用http DELETE并没有那么滥用,因此甚至有人建议在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天全站免登陆