How send Form params to REST web-service through H

2019-09-08 15:11发布

问题:

I can tranfer HeaderParam's and QueryParam's. But how can I attach to HTTP client FormParam's?

    private String addFormParams(Map<String, Object> formParams) {
        JSONObject jsonObject = new JSONObject();
        for (Map.Entry<String, Object> param : formParams.entrySet()) {
            try {
                jsonObject.put(param.getKey(), param.getValue());
            } catch (JSONException e) {
                Log.e(TAG, "JSONException " + e);
            }
        }
        return jsonObject.toString();
    }

StringEntity stringEntity = new StringEntity(addFormParams(formParams));
            mHttpPost.setEntity(stringEntity);

It doesnt work.Is this right approach?