cURL and HttpURLConnection - Post JSON Data

后端 未结 2 1257
走了就别回头了
走了就别回头了 2020-12-02 12:55

How to post JSON data using HttpURLConnection? I am trying this:

HttpURLConnection httpcon = (HttpURLConnection) ((new URL(\"a url\").openConnection()));
htt         


        
2条回答
  •  眼角桃花
    2020-12-02 13:04

    You may want to use the OutputStreamWriter class.

    final String toWriteOut = "{'value': 7.5}";
    final OutputStreamWriter osw = new OutputStreamWriter(connection.getOutputStream());
    osw.write(toWriteOut);
    osw.close();
    

提交回复
热议问题