我为HTTP-Request编写了一个类。 我的问题是,尽管在这段代码的几行中我添加了:
httpConn.setRequestMethod("PUT");
我的代码仍然执行POST-Request而不是PUT-Request!我错了什么?谢谢!
public MultipartUtility(String requestURL, String charset)
throws IOException {
this.charset = charset;
// creates a unique boundary based on time stamp
boundary = "===" + System.currentTimeMillis() + "===";
URL url = new URL(requestURL);
httpConn = (HttpURLConnection) url.openConnection();
httpConn.setUseCaches(false);
httpConn.setRequestMethod("PUT");
httpConn.setDoOutput(true); // indicates POST method
httpConn.setRequestMethod("PUT");
httpConn.setDoInput(true);
httpConn.setRequestProperty("Content-Type",
"multipart/form-data; boundary=" + boundary);
httpConn.setRequestProperty("User-Agent", "CodeJava Agent");
httpConn.setRequestProperty("Test", "Bonjour");
outputStream = httpConn.getOutputStream();
writer = new PrintWriter(new OutputStreamWriter(outputStream, charset),
true);
}
答案 0 :(得分:1)
httpConn.setUseCaches(false);
可以影响此结果。我不确定PUT
是否可以提供此功能