为什么以下代码会执行GET
次请求,而不是POST
次请求。我还收到了CONTENT_TYPE:"" :(
HashMap<String, String> PostDataMap = new HashMap<>();
PostDataMap.put("method","any");
String PostDataString = HTTPEncodeParamNameValues(PostDataMap);
URL url = new URL(ApiServerURL);
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setDoInput(true);
httpURLConnection.setDoOutput(true);
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
httpURLConnection.setUseCaches(false);
DataOutputStream dataOutputStream = new DataOutputStream(httpURLConnection.getOutputStream());
dataOutputStream.writeBytes(PostDataString);
dataOutputStream.flush();
dataOutputStream.close();
InputStream inputStream = url.openConnection().getInputStream();
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length;
while ((length = inputStream.read(buffer)) != -1) {
byteArrayOutputStream.write(buffer, 0, length);
}
答案 0 :(得分:0)
当您将一些用户输入传递给服务器时,发布并且仅获取数据无用户输入该时间使用获取强>
当使用获取时,所有数据都会在 url 中调用。它有限的尺寸。并且不安全。 当您使用发布时,不会将数据转换为网址。 无限数据即可发送。也安全。