java 调用webapi json_java通过url调用web api并接收其返回的json
java通過url調(diào)用webapi并接收其返回的json數(shù)據(jù),但現(xiàn)在結(jié)果總是:{"result":4,"data":{}}(未認(rèn)證:),幫助文檔如下:API使用方法WebAPI使用是通過GET或者POST方法,將數(shù)據(jù)傳送給光盤...
java通過url調(diào)用web api并接收其返回的json數(shù)據(jù),但現(xiàn)在結(jié)果總是: {"result":4,"data":{}}(未認(rèn)證:),幫助文檔如下:
API 使用方法
Web API 使用是通過GET 或者POST 方法,將數(shù)據(jù)傳送給光盤庫服務(wù)器的函數(shù)。請(qǐng)留意如下內(nèi)
容使用Web API:
? 使用GET方法時(shí)
為了維護(hù)Session,請(qǐng)使用Cookie。
? 使用POST方法時(shí)
為了維護(hù)Session,請(qǐng)使用Cookie。
另外,登陸認(rèn)證用數(shù)據(jù)時(shí),請(qǐng)傳送“authenticity_token”
“authenticity_token”包含“+”等符號(hào),請(qǐng)使用適當(dāng)?shù)木幋a。
我不明白,大家?guī)兔χ更c(diǎn)下,謝謝~~如下是我的讀取json數(shù)據(jù)的代碼:
public String getJsonString(String urlPath) {
HttpURLConnection connection = null;
StringBuffer sb = new StringBuffer("");
String str = null,str1 = null;
try {
URL url = new URL(urlPath);
connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);//允許連接提交信息
connection.setDoInput(true);
connection.setUseCaches(false);
connection.setInstanceFollowRedirects(true);
connection.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded");
connection.connect();
InputStream inputStream = connection.getInputStream();
// 對(duì)應(yīng)的字符編碼轉(zhuǎn)換
Reader reader = new InputStreamReader(inputStream, "UTF-8");
BufferedReader bufferedReader = new BufferedReader(reader);
sb = new StringBuffer();
while ((str = bufferedReader.readLine()) != null) {
sb.append(str);
}
reader.close();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
connection.disconnect();
return str;
}
展開
總結(jié)
以上是生活随笔為你收集整理的java 调用webapi json_java通过url调用web api并接收其返回的json的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 黄蜂酒的功效与作用、禁忌和食用方法
- 下一篇: java 分句_JAVA按文字,标点符号