【问题标题】:HttpUrlConnection with post request and parameter as JSON object?HttpUrlConnection 与 post 请求和参数作为 JSON 对象?
【发布时间】:2018-06-23 22:53:52
【问题描述】:

here 提出了同样的问题,但我想提出一个具有以下结构的请求。

"method": "post",

"url": parserApiUrl,

"data": {

"url": s3BaseUrl + imageKey

},

"headers": {

"x-api-key": "sdsdasdwdw"

}

【问题讨论】:

标签: java android json


【解决方案1】:

我通过这个步骤找到了解决方案

urlConnection = (HttpURLConnection) url
                        .openConnection();
                urlConnection.setDoOutput(true);
                urlConnection.setRequestMethod("POST");
                urlConnection.setRequestProperty("Content-Type", "application/json");
                urlConnection.setRequestProperty("x-api-key", x_api);
                urlConnection.setRequestProperty("Accept", "application/json");

                String datajson =  "{\"file\": \""+imageString.trim()+"\"}";
                Log.e("data","json:"+datajson);

                OutputStream os = urlConnection.getOutputStream();
                os.write(datajson.getBytes("UTF-8"));
                os.close();

【讨论】:

    猜你喜欢
    • 2013-06-03
    • 2018-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多