【问题标题】:Getting 400 volley server error which is working from Rest client successfully从 Rest 客户端成功获取 400 volley server 错误
【发布时间】:2015-05-08 14:02:08
【问题描述】:

以下 url 的 volley get 请求出现 400 服务器错误

http://query.yahooapis.com/v1/public/yql?q=select * from yahoo.finance.xchange where pair in ('AEDALL')&format=json&env=store://datatables.org/alltableswithkeys&callback=

当我从其他客户端点击相同的 url 时,它会给出 json 响应

这是我的凌空请求代码

private void convertCurrenctVolleyTask(String from, final String to, final String amount) {

    String url_yahoo = "http://query.yahooapis.com/v1/public/yql?q=select * from yahoo.finance.xchange where pair in ('"+from+to+"')&format=json&env=store://datatables.org/alltableswithkeys&callback=";

    final ProgressDialog progressDialog;
    progressDialog = new ProgressDialog(CurrencyConverter.this);
    progressDialog.setMessage("Please wait...");
    progressDialog.setCancelable(true);
    progressDialog.show();

    JsonObjectRequest GetCurrenciesjsObjRequest = new JsonObjectRequest(
            Request.Method.GET, url_yahoo, null,
            new Response.Listener<JSONObject>() {

                @Override
                public void onResponse(JSONObject response) {
                    progressDialog.cancel();
                    if (response != null) {
                            parseGetCurrencyResp(response,to,amount);

                    }
                }
            }, new Response.ErrorListener() {

                @Override
                public void onErrorResponse(VolleyError error) {
                    progressDialog.cancel();
                    Toast.makeText(CurrencyConverter.this,
                            "Server error..", Toast.LENGTH_SHORT).show();
                    error.printStackTrace();

                }
            });

    ConfigVolley.getInstance().addToRequestQueue(GetCurrenciesjsObjRequest);

}

任何帮助表示赞赏

【问题讨论】:

    标签: android android-volley yahoo-api yahoo-finance


    【解决方案1】:

    您需要将所有出现的空格(“”)替换为 %20 url_yahoo = url_yahoo.replace(" ", "%20");

    【讨论】:

    • 欢迎您,如果您不介意可以接受答案,因为它有效。
    • 我的 Phusion Passenger 服务器出现了一个非常奇怪的错误。只是带有“无效常量字符串”的“400”响应,但仅限于 Android
    【解决方案2】:

    这不是一个格式正确的 URL。您需要对 URL 参数进行编码,使其不包含无效字符。

    在使用 url_yahoo 之前尝试使用 URLEncoder,如下所示:

    String query = "select * from yahoo.finance.xchange where pair in ('"+from+to+"')";
    query = URLEncoder.encode(query, "utf-8");
    
    String env = "store://datatables.org/alltableswithkeys&callback=";
    env = URLEncoder.encode(query, "utf-8");
    
    url_yahoo = "http://query.yahooapis.com/v1/public/yql?q=" + query + "&format=json&env=" + env;
    

    【讨论】:

    • 感谢您的回复,我正在使用相同的 400 05-08 20:09:11.902: E/Volley(7509): [47873] BasicNetwork.performRequest: Unexpected response code 400 for @ 987654322@*+from+yahoo.finance.xchange+where+pair+in+%28%27AEDAMD%27%29&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys%26callback%3D
    猜你喜欢
    • 2019-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-04
    • 1970-01-01
    • 2011-11-23
    • 2016-03-20
    • 1970-01-01
    相关资源
    最近更新 更多