java-http-client

Allow insecure HTTPS connection for Java JDK 11 HttpClient

余生颓废 提交于 2019-11-27 02:13:03
问题 Sometimes it is needed to allow insecure HTTPS connections, e.g. in some web-crawling applications which should work with any site. I used one such solution with old HttpsURLConnection API which was recently superseded by the new HttpClient API in JDK 11. What is the way to allow insecure HTTPS connections (self-signed or expired certificate) with this new API? UPD: The code I tried (in Kotlin but maps directly to Java): val trustAllCerts = arrayOf<TrustManager>(object: X509TrustManager {

How to upload a file using Java HttpClient library working with PHP

不羁的心 提交于 2019-11-25 23:16:26
问题 I want to write Java application that will upload a file to the Apache server with PHP. The Java code uses Jakarta HttpClient library version 4.0 beta2: import java.io.File; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.HttpVersion; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.FileEntity; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.params