try {
URL url = new URL(urlStr);
HttpURLConnection httpURLConnection = (HttpURLConnection) url
.openConnection(); //獲取連接
httpURLConnection.setRequestMethod("GET"); //設置請求方法爲POST, 也可以爲GET
httpURLConnection.setDoOutput(true);
InputStream is = httpURLConnection.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
while (br.read() != -1) {
sb.append(br.readLine());
}
content = new String(sb);
content = new String(content.getBytes("GB2312"), "ISO-8859-1");
br.close();
} catch (Exception e) {
throw new Exception("付款接口調用失敗!");
}
// 以上爲調用的遠程接口,數據傳輸格式爲JSON
JSONObject jsonObject = JSONObject.fromObject("{" + content);
String expenseCode = jsonObject.getString("expense_code");