将get请求中的JSON数据作为请求体传递

编程入门 行业动态 更新时间:2024-10-27 16:29:05
本文介绍了将get请求中的JSON数据作为请求体传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

您好我必须向网址发送获取请求 http:/ /onemoredemo.appspot/group?authToken=access_token&authMethod=oauth

Hi i have to send a get request to an url onemoredemo.appspot/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("onemoredemo.appspot/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"); conn.addRequestProperty("Content-TYpe", "application/json"); conn.getOutputStream().write(jj.toString().getBytes()); conn.connect(); InputStream is=conn.getInputStream();

我收到错误 java.io.FileNotFoundException 。

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

I sent a request from mozilla browser to url onemoredemo.appspot/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.

推荐答案

不要这样做。

阅读: tech.groups.yahoo/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:

stackoverflow/a/978094/550967

stackoverflow/a/978173/550967

stackoverflow/a/978519/550967

更多推荐

将get请求中的JSON数据作为请求体传递

本文发布于:2023-10-29 13:24:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1539808.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据   JSON

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!