【发布时间】:2018-12-01 22:25:32
【问题描述】:
准确地说我想在curl下面执行一个返回json和java的动作:
curl -H 'Client-ID: ahh_got_ya' -X GET 'https://api.twitch.tv/helix/streams'
这在 linux shell 中运行良好。
下面是我尝试使用 java json 在 curl 上做的脚本:
{String urly = "https://api.twitch.tv/helix/streams";
URL obj = new URL(urly);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("GET");
con.setRequestProperty("Content-Type","application/json");
con.setRequestProperty("Client-ID","Ahh_got_ya");
con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.writeBytes("");
wr.flush();
wr.close();
int responseCode = con.getResponseCode();
System.out.println("Response Code : " + responseCode);
BufferedReader iny = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String output;
StringBuffer jsonres = new StringBuffer();
while ((output = iny.readLine()) != null) {
jsonres.append(output);
}
iny.close();
//printing result from response
System.out.println(response.toString());
}
我收到:java.io.FileNotFoundException: https://api.twitch.tv/helix/streamsResponse Code : 404
非常感谢所有回复。
【问题讨论】:
-
什么是“java json”?
-
@GeorgeJempty 在 java 中使用 json 执行 curl
-
“java json”中的“curl”在哪里
-
@GeorgeJempty
curl在 linux shell 中使用,你可以用它来指定包头、内容等,并做 httpGET和POST的东西。所以问题是:我想制作与上面 curl 命令制作的类似的数据包。 -
我知道这一切。你的措辞方式完全没有意义。特别是“使用 json”,这与使用 Java 中的 curl 无关。回想起来,我应该投票结束,理由是这“太宽泛”,而不是“不清楚”