Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法将post请求更改为put请求_Java_Http - Fatal编程技术网

Java 无法将post请求更改为put请求

Java 无法将post请求更改为put请求,java,http,Java,Http,我为我的HTTP请求编写了一个类。 我的问题是,尽管在这段代码的几行中我添加了: httpConn.setRequestMethod("PUT"); 我的代码仍然执行POST请求而不是PUT请求!我错了什么?谢谢 public MultipartUtility(String requestURL, String charset) throws IOException { this.charset = charset; // create

我为我的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
能否提供此功能

httpConn.setUseCaches(false);可以影响这个结果。我不确定PUT能否提供这一点feature@Adem你是对的!请写一个答案,这样我就可以给它打分了!谢谢