如何使用名称值对和http URL连接将数据发布到外部数据库?

时间:2015-12-01 07:11:57

标签: android

我没有任何正确的代码将数据发送到StorageFile中的外部数据库,因为API level 23方法已被弃用。请帮我。我很久以前就被困在这里了。

1 个答案:

答案 0 :(得分:0)

您可以使用StringRequest,例如:

public static JSONObject sendRequestGetReserves(RequestQueue requestQueue)
        throws InterruptedException, ExecutionException, TimeoutException, JSONException {


    JSONObject response = null;

    RequestFuture<String> requestFuture = RequestFuture.newFuture();

    StringRequest strRequest = new StringRequest(Request.Method.POST,
            "Your url", requestFuture, requestFuture) {
        @Override
        protected Map<String, String> getParams() {
            Map<String, String> params = new HashMap<>();
            params.put("Your NameValuePair1", "value1");
            params.put("Your NameValuePair2", "value2");
            return params;
        }
    };

    requestQueue.add(strRequest);

    response = new JSONObject(requestFuture.get(30000, TimeUnit.MILLISECONDS));

    return response;
}