gpt4 book ai didi

java - 如何通过 Java BufferedReader 从 Nexmo.com get-balance API 获取正确的 XML 页面?

转载 作者:太空宇宙 更新时间:2023-11-04 08:14:57 24 4
gpt4 key购买 nike

我尝试调用 Nexmo.com 的 get-balance web/RESTful API 来获取帐户余额,但收到两种错误响应:(1)400 - 在 GAE-Java runtme 中找不到页面。 (2)Java SE 运行时中的FileNotFoundException。如何通过Java BufferedReader获取正确的XML页面?

String api =  "http://rest.nexmo.com/account/get-balance/{idkey}/{pwkey}";
URL url = new URL(api);
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
while ((line = reader.readLine()) != null) {
...

最佳答案

    String strURL = "http://rest.nexmo.com/account/get-balance/";
strURL += USERNAME + "/" + PASSWORD;
GetMethod get = new GetMethod(strURL);
get.addRequestHeader("Accept", "application/xml");
HttpClient httpclient = new HttpClient();
try {
int result = httpclient.executeMethod(get);
System.out.println("Response status code: " + result);
String responseBodyAsString = get.getResponseBodyAsString();
System.out.println("responseBodyAsString: " + responseBodyAsString);
} finally {
get.releaseConnection();
}

关于java - 如何通过 Java BufferedReader 从 Nexmo.com get-balance API 获取正确的 XML 页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10593465/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com