D
D
DeNissss44442021-11-30 17:47:01
Java
DeNissss4444, 2021-11-30 17:47:01

How to work with object of type multipart/form-data in Java 11?

I am writing in java 11 and for api requests I use the built-in java.net.http.HttpRequest; And now I want to upload a picture to the VK wall via api. According to the documentation, I need an object of the multipart/form-data type for this. I did not find how to work with such an object through java.net.http.HttpRequest. Therefore, I had a question with it is generally possible to work with it without loading any third-party libraries, but using pure Java 11 or not? If possible, how? My method looks like this now

try {
            postRequest = HttpRequest.newBuilder()
                    .uri(URI.create(url))
                    .POST(HttpRequest.BodyPublishers.noBody())
                    .header("Content-Type", "multipart/form-data")
                    .build();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question