100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > java 调用webapi json_java通过url调用web api并接收其返回的json

java 调用webapi json_java通过url调用web api并接收其返回的json

时间:2022-11-04 23:02:40

相关推荐

java 调用webapi json_java通过url调用web api并接收其返回的json

java通过url调用webapi并接收其返回的json数据,但现在结果总是:{"result":4,"data":{}}(未认证:),帮助文档如下:API使用方法WebAPI使用是通过GET或者POST方法,将数据传送给光盘...

java通过url调用web api并接收其返回的json数据,但现在结果总是: {"result":4,"data":{}}(未认证:),帮助文档如下:

API 使用方法

Web API 使用是通过GET 或者POST 方法,将数据传送给光盘库服务器的函数。请留意如下内

容使用Web API:

 使用GET方法时

为了维护Session,请使用Cookie。

 使用POST方法时

为了维护Session,请使用Cookie。

另外,登陆认证用数据时,请传送“authenticity_token”

“authenticity_token”包含“+”等符号,请使用适当的编码。

我不明白,大家帮忙指点下,谢谢~~如下是我的读取json数据的代码:

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();

// 对应的字符编码转换

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;

}

展开

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。