Working POST Multipart Request with Volley and without HttpEntity

前端 未结 5 1376
隐瞒了意图╮
隐瞒了意图╮ 2020-11-22 09:55

This is not really a question, however, I would like to share some of my working code here for your reference when you need.

As we know that HttpEntity

5条回答
  •  长情又很酷
    2020-11-22 10:34

    For those who are struggling to send utf-8 parameters and still no luck, the problem I had was in the dataOutputStream, and change the code of @RacZo to below code:

    private void buildTextPart(DataOutputStream dataOutputStream, String parameterName, String parameterValue) throws IOException {
            dataOutputStream.writeBytes(twoHyphens + boundary + lineEnd);
            dataOutputStream.writeBytes("Content-Disposition: form-data; name=\"");
            dataOutputStream.write(parameterName.getBytes("UTF-8"));
            dataOutputStream.writeBytes(lineEnd);
            dataOutputStream.writeBytes("Content-Type: text/plain; charset=UTF-8" + lineEnd);
            dataOutputStream.writeBytes(lineEnd);
            dataOutputStream.write(parameterValue.getBytes("UTF-8"));
            dataOutputStream.writeBytes(lineEnd);
        } 
    

提交回复
热议问题