【问题标题】:Android Volley request failing while making a call to wit.ai API调用 wit.ai API 时 Android Volley 请求失败
【发布时间】:2019-01-25 15:43:36
【问题描述】:

我正在尝试使用 wit.ai 的语音识别 REST API 服务

我使用 Volley 向 URL 发送 POST 请求 https://api.wit.ai/speech

这是我目前所做的:

void makeApiCall(){
    StringRequest request =  new StringRequest(Request.Method.POST, "https://api.wit.ai/speech", new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            Log.d("wit_response",response);
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.d("wit_response",error.toString());
        }
    }){
        @Override
        protected Map<String,String> getParams() throws AuthFailureError{
            Map<String,String> params = new HashMap<>();
            params.put("Authorization","Bearer XXXXXX"); //hidden my token
            params.put("Content-Type","audio/mpeg3");
            return params;
        }
        @Override
        public byte[] getBody() throws AuthFailureError {

            return sendToByte();
        }
    };



    RequestQueue queue = Volley.newRequestQueue(getApplicationContext());
    queue.add(request);
}

我在 onErrorResponse() 方法内的 wit_response 日志键上收到 com.android.volley.ClientError 错误

我没有错过内容类型和授权标头,并且我的 sendToByte 函数成功返回了一个转换为字节数组的 mp3 文件。

有什么问题?

【问题讨论】:

  • 您是否尝试过在 Postman 或 Restlet 等单独的 Rest 客户端中进行相同的 Post 调用?

标签: android rest android-volley wit.ai


【解决方案1】:

我不得不使用这个链接https://gist.github.com/anggadarkprince/a7c536da091f4b26bb4abf2f92926594

并使用本文所述的 MultiPartRequest 类上传我的文件。

如果您需要任何帮助(对于所有未来的人),请在此处发表评论

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-12-22
    • 2021-06-04
    • 2015-06-17
    • 2015-06-11
    • 2021-03-10
    • 2016-09-10
    • 1970-01-01
    • 2013-11-12
    相关资源
    最近更新 更多