我正在尝试使用邮政发送gzip编码的数据,但每次都会收到400响应
我尝试了以下代码
conn = (HttpURLConnection)url.openConnection();
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setRequestProperty("Authorization", parameters[1]);
conn.setRequestProperty("Content-Encoding", "gzip");
ByteArrayOutputStream baos = new ByteArrayOutputStream(messageBody.length());
GZIPOutputStream gzip = new GZIPOutputStream(baos);
gzip.write(messageBody.getBytes(Charset.forName("UTF-8")));
OutputStream os = conn.getOutputStream();
os.write(baos.toByteArray());
os.close();
gzip.close();
conn.connect();
int res = conn.getResponseCode();
响应代码始终为400。请帮助。