如何在android中使用curl-url进行json-api集成


How to use curl url for json api integration in android

我已经被困很多天了。我想在我的android应用程序中使用informedica的api。但我不知道如何使用curl它的卷曲url是

curl-X GET--标头"Accept:application/json"--标头"app_id:90f10c6a"--标头"app_key:9d23d9250d9f2ee8aa49efda732e4d3d"https://api.infermedica.com/v2/symptoms"

请求Url为

https://api.infermedica.com/v2/symptoms

当我试图打开请求url链接时,我得到了身份验证参数丢失错误

请引导我!

提前感谢!

使用Volley执行cURL请求。

private void getResponse(){
    String URL = "https://api.infermedica.com/v2/symptoms";
    RequestQueue queue = Volley.newRequestQueue(this);
    StringRequest request = new StringRequest(Request.Method.GET, URL,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    Log.e("Check Response",response);
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Log.e("Check Error","Error");
                }
            }
    ){
        @Override
        public byte[] getBody() throws AuthFailureError {
            return new byte[]{};
        }
        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            Map<String,String> map = new HashMap<>();
            map.put("Content-Type","application/json");
            map.put("Accept", "application/json");
            map.put("app_id","90f10c6a");
            map.put("app_key","9d23d9250d9f2ee8aa49efda732e4d3d");
            return map;
        }
    };
    request.setRetryPolicy(new DefaultRetryPolicy(15000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_MAX_RETRIES));
    queue.add(request);
}

这是我获取JSON对象的函数

public JSONObject getJSONFromUrl(String url)
 {
    // Making HTTP request
    try {
        // defaultHttpClient
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost(url);
        HttpResponse httpResponse = httpClient.execute(httpPost);
        HttpEntity httpEntity = httpResponse.getEntity();
        is = httpEntity.getContent();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(
                is, "iso-8859-1"), 8);
        StringBuilder sb = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) {
            sb.append(line + "'n");
        }
        is.close();
        json = sb.toString();
    } catch (Exception e) {
        Log.e("Buffer Error", "Error converting result " + e.toString());
    }
    // try parse the string to a JSON object
    try {
        jObj = new JSONObject(json);
    } catch (JSONException e) {
        Log.e("JSON Parser", "Error parsing data " + e.toString());
    }
    // return JSON String
    return jObj;

}

我如何在其中添加您的代码?