Java http協議呼叫介面返回json字串
/**
* 字串引數
* @param url
* @return
*/
public static String loadJSON (String url) {
StringBuilder json = new StringBuilder();
try {
URL oracle = new URL(url);
URLConnection yc = oracle.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(
yc.getInputStream()));
String inputLine = null;
while ( (inputLine = in.readLine()) != null) {
json.append(inputLine);
}
in.close();
} catch (MalformedURLException e) {
} catch (IOException e) {
}
return json.toString();
* 字串引數
* @param url
* @return
*/
public static String loadJSON (String url) {
StringBuilder json = new StringBuilder();
try {
URL oracle = new URL(url);
URLConnection yc = oracle.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(
yc.getInputStream()));
String inputLine = null;
while ( (inputLine = in.readLine()) != null) {
json.append(inputLine);
}
in.close();
} catch (MalformedURLException e) {
} catch (IOException e) {
}
return json.toString();
}
public
static
void
main(String[] args) {
String url =
"http://192.168.1.256/userlogin?userid=1&username=2"
;
String json = loadJSON(url);
System.out.println(json);
}
相關文章
- java通過url呼叫遠端介面返回json資料JavaJSON
- HTTP 協議HTTP協議
- [HTTP協議]HTTP協議
- http協議HTTP協議
- Java介面 == Objective-C協議JavaObject協議
- java 請求HTTP返回json集合,物件處理方式JavaHTTPJSON物件
- golang通過反射使用json字串呼叫struct的指定方法及返回json結果Golang反射JSON字串Struct
- RTSP協議、RTMP協議、HTTP協議的區別協議HTTP
- http協議分析HTTP協議
- 理解http協議HTTP協議
- HTTP協議概述HTTP協議
- HTTP 協議類HTTP協議
- HTTP協議(2)HTTP協議
- 小解http協議HTTP協議
- 02 前端HTTP協議(圖解HTTP) 之 簡單的HTTP協議前端HTTP協議圖解
- gRPC 之流式呼叫原理 http2 協議分析(四)RPCHTTP協議
- Http介面呼叫示例教程HTTP
- #「HTTP 協議」90%的java程式設計師都看得懂的最全HTTP 協議講解HTTP協議Java程式設計師
- 兩種介面傳送資料協議(xml和json)協議XMLJSON
- HTTP 協議圖解HTTP協議圖解
- 瞭解HTTP協議HTTP協議
- HTTP協議那些事HTTP協議
- HTTP協議簡述HTTP協議
- HTTP 協議簡介HTTP協議
- Http協議簡介HTTP協議
- HTTP2 協議HTTP協議
- 簡述HTTP協議HTTP協議
- HTTP 協議完全解析HTTP協議
- HTTP協議基礎HTTP協議
- Http協議入門HTTP協議
- HTTP通訊協議HTTP協議
- 淺談HTTP協議HTTP協議
- HTTP 協議入門HTTP協議
- 圖解 HTTP 協議圖解HTTP協議
- http協議內容HTTP協議
- HTTP 協議詳解HTTP協議
- HTTP協議概念篇HTTP協議
- HTTP協議詳解HTTP協議