你好,我需要向一个URL发送GET请求:
http://onemoredemo.appspot.com/group?authToken=access_token&authMethod=oauth
请求体需要包含如下JSON对象。
{"goupid":"some_variable"
}
以下是发送GET请求的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
它给我正确的响应,但现在已经过去一个多小时,所以accesstoken已经过期。我知道在get请求中同时发送参数和请求体很奇怪,但我必须这样发送。
请帮忙解决如何在get请求的请求体中发送json对象的问题。
get.
是什么意思? - Jon Taylor