GET http: // localhost / res / image / 1001- allows you to download a picture (jpg file) for resource number one thousand one
POST http: // localhost / res / image / 1001- accept and save (replace if there was) a picture
DELETE http: // localhost / res / image / 1001- delete accordingly
InputStream serverInput = ClientHttpRequest.post(
new java.net.URL(urlString),
new Object[]{
"name", "J.Doe",
"email", "abuse@spamcop.com",
"test.txt", new
File("c:\w\image.jpg")
});
-----------------------------k8rws1oxpkuv1g53x0ud6a004-j12py3q5jcay
Content-Disposition: form-data; name="name"
J.Doe
-----------------------------k8rws1oxpkuv1g53x0ud6a004-j12py3q5jcay
Content-Disposition: form-data; name="email"
abuse@spamcop.com
-----------------------------k8rws1oxpkuv1g53x0ud6a004-j12py3q5jcay
Content-Disposition: form-data; name="test.txt"; filename="image.jpg"
Content-Type: image/jpeg
...
ServletFileUpload upload = new ServletFileUpload();
FileItemIterator iter = upload.getItemIterator(httpServletRequest);
while (iter.hasNext()) {
FileItemStream item = iter.next();
if (!item.isFormField()) {
InputStream stream = item.openStream();
//
}
}
* This source code was highlighted with Source Code Highlighter .
Source: https://habr.com/ru/post/50406/
All Articles