9 Mayıs 2019 Perşembe

HttpClient Sınıfı - Kullanmayın

Giriş
Şu satırı dahil ederiz.
import org.apache.commons.httpclient.HttpClient;
Açıklaması şöyle
Commons HttpClient is an old project that produced HttpClient 3.1. The project was subsumed by the larger Apache HttpComponents project, which produced HttpClient 4.x.
constructor
Şöyle yaparız.
HttpClient client = new HttpClient ();
execute metodu

Örnek - Multipart file uploads
Şöyle yaparız
File file1 = new File("C:\\_tools\\students.xml");
File file2 = new File("C:\\_tools\\rules.xml");

PostMethod filePost = new PostMethod(url);
Part[] parts = {
 new FilePart(file1.getName(), file1),
 new FilePart(file2.getName(), file2)
};
filePost.setRequestEntity(
  new MultipartRequestEntity(parts, filePost.getParams())
);
HttpClient client = new HttpClient();
int status = client.executeMethod(filePost);
Örnek - HttpPost
Şöyle yaparız.
StringEntity entity = ...
HttpPost post = new HttpPost(URL);
post.setEntity(entity);
HttpResponse response = client.execute(post);

Hiç yorum yok:

Yorum Gönder