我为我的http请求编写了一个类。
我的问题是,尽管在这段代码的几行中,我添加了:

httpConn.setRequestMethod("PUT");

我的代码仍然执行POST请求而不是PUT请求!我做错什么了?谢谢!
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);
    }

最佳答案

httpConn.setUseCaches(false);会影响此结果。我不确定PUT是否可以提供此功能

10-05 19:01