将get请求中的JSON数据作为请求体传递 [英] Passing JSON data in get request as request body

查看:8602
本文介绍了将get请求中的JSON数据作为请求体传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我必须向网址发送获取请求

http:/ /onemoredemo.appspot.com/group?authToken=access_token&authMethod=oauth

Hi i have to send a get request to an url
http://onemoredemo.appspot.com/group?authToken=access_token&authMethod=oauth

请求正文包含json对象,如下所示。

with request body contains json object as shown below.

{"goupid":"some_variable"
}

以下是发送获取请求的java代码部分:

Here is a section of java code for sending get request:

URL url1=new URL("http://onemoredemo.appspot.com/group?authToken="+access_token+"&authMethod=oauth");
conn=(HttpURLConnection) url1.openConnection();
conn.addRequestProperty("Content-type", "application/x-www-form-urlencoded");

conn.setRequestMethod("GET");
conn.setDoOutput(true);
JSONObject jj=new JSONObject();
HttpGet get;
get.

jj.put("groupid", "testing@iritesh.com");
conn.addRequestProperty("Content-TYpe", "application/json");
conn.getOutputStream().write(jj.toString().getBytes());
conn.connect();
InputStream is=conn.getInputStream();

我收到错误 java.io.FileNotFoundException

我从mozilla浏览器发送请求到url

http://onemoredemo.appspot.com/group?authToken=ya29.AHES6ZRDl-RqiA8W0PhybU_hMluHrHRjlJBvq06Vze0izJq0Ovjc088&authMethod=oauth 点击
这是给我正确的回应,但现在它超过一个小时,所以acccesstoken到期。我知道在get请求中发送参数以及requestbody但我必须发送它很奇怪。

I sent a request from mozilla browser to url
http://onemoredemo.appspot.com/group?authToken=ya29.AHES6ZRDl-RqiA8W0PhybU_hMluHrHRjlJBvq06Vze0izJq0Ovjc088&authMethod=oauth
It was giving me correct response but now its more than one hour so acccesstoken expire. I know its weird to send parameter as well as requestbody in get request but i have to send it.

请帮助我们在get请求中如何在请求体中发送json对象。

Please help in how to send a json object in request body in get request.

推荐答案

不要这样做。

阅读:
http://tech.groups.yahoo.com/group/rest-discuss/message/9962


是的。换句话说,任何HTTP请求消息都允许包含
消息体,因此必须解析消息,并考虑到这一点。但是,GET的b $ b语义是受限制的,因为一个主体(如果有的话)
对请求没有语义含义。解析
的要求与方法语义的要求是分开的。

"Yes. In other words, any HTTP request message is allowed to contain a message body, and thus must parse messages with that in mind. Server semantics for GET, however, are restricted such that a body, if any, has no semantic meaning to the request. The requirements on parsing are separate from the requirements on method semantics.

所以,是的,你可以发送一个带有GET的主体,不,它对
来说永远不会有用。

So, yes, you can send a body with GET, and no, it is never useful to do so.

这是HTTP / 1.1的分层设计的一部分,一旦规范被分区,它将再次变得清晰
(工作我n进展)。

This is part of the layered design of HTTP/1.1 that will become clear again once the spec is partitioned (work in progress)."

关于此检查的其他有趣讨论:

For other interesting discussions on this check this:

https://stackoverflow.com/a/978094/550967

https://stackoverflow.com/a/978173/550967

https://stackoverflow.com/a/978519/550967

这篇关于将get请求中的JSON数据作为请求体传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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