加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 以请求身份在获取请求中传递JSON数据

发布时间:2020-12-14 19:27:36 所属栏目:Java 来源:网络整理
导读:嗨,我必须向url发送获取请求 http://onemoredemo.appspot.com/group?authToken=access_tokenauthMethod=oauth 请求体包含json对象,如下所示. {"goupid":"some_variable"} 以下是发送获取请求的一段java代码: URL url1=new URL("http://onemoredemo.appspot.
嗨,我必须向url发送获取请求
http://onemoredemo.appspot.com/group?authToken=access_token&authMethod=oauth

请求体包含json对象,如下所示.

{"goupid":"some_variable"
}

以下是发送获取请求的一段java代码:

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到期.我知道它有奇怪的发送参数以及请求的请求,但我必须发送它.

请帮助如何在请求体中发送json对象以获取请求.

解决方法

不要这样做

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

“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.

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

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

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

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

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读