1

I tried to call a get-balance web/ RESTful API of Nexmo.com to get account's balance, but I received two kind of error response: (1)400 - page not found in GAE-Java runtme. (2)FileNotFoundException in Java SE runtime. How to get the correct XML page by Java BufferedReader?

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) {
...
4

3 回答 3

1
    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();
    }
于 2012-08-10T07:45:17.220 回答
0

我有同样的问题。您唯一需要做的就是在请求中添加“Accept”标头:

GetMethod get = new GetMethod("https://rest.nexmo.com/account/get-balance/{key}/{secret}");
HttpClient client = new HttpClient();

try {
    get.addRequestHeader("Accept", "application/xml"); //OR "application/json"
    int status = client.executeMethod(get);
    ...

希望能帮助到你!!

于 2012-05-21T16:33:47.953 回答
0

我相信您获得 404 的唯一方法是如果keyorsecret丢失:

http://rest.nexmo.com/account/get-balance/[key]/[secret]

你确定他们都被设置了吗?

标准免责声明:我为 Nexmo 做一些开发人员宣传。

于 2012-05-15T05:18:55.760 回答