_cCertifikatZPKomunikace". " --cacert $this->_cCertifikatPortalCA". " --data \"reques...">

CURL equivalent in Java

I had

exec( "curl". " --cert $this->_cCertifikatZPKomunikace". " --cacert $this->_cCertifikatPortalCA". " --data \"request=".urlencode($fc_xml)."\"". " --output $lc_filename_stdout". " $this->_cPortalURL". " 2>$lc_filename_stderr", $la_dummy,$ln_RetCode ); 

in php.

I need to do this through java. Can you help me?

Thanks Jakub

+4
source share
6 answers

I use the HttpClient methods:

 import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpMethod; import org.apache.commons.httpclient.methods.GetMethod; 

So:

 HttpClient client = new HttpClient(); HttpMethod method = new GetMethod("http://www.google.com"); int responseCode = client.executeMethod(method); if (responseCode != 200) { throw new HttpException("HttpMethod Returned Status Code: " + responseCode + " when attempting: " + url); } String rtn = StringEscapeUtils.unescapeHtml(method.getResponseBodyAsString()); 

EDIT: Oh. StringEscapeUtils comes from commons-lang. http://commons.apache.org/lang/api/org/apache/commons/lang/StringEscapeUtils.html

+14
source

Take a look at URLConnection . Sun has some examples . It has various subclasses that support some specific HTTP and HTTPS functions.

+3
source

in addition to the pure Java answers of Quotidian and Yacoby, you can try to execute curl binary, as in php. Learn how to use the ProcessBuilder class.

+2
source

You can execute Java commands using Runtime with a call to getRuntime()

link to javadoc to execute.

Here is a decent example of using runtime.

Here is an example of a decent example using Runtime or ProcessBuilder.

I hope this is helpful.

+2
source

The cURL site references Java bindings on Github.

+1
source

You can use the HtmlUnit API in Java

 import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.html.HtmlPage; 

So:

 WebClient webClient = new WebClient(); HtmlPage homePage = webClient.getPage("http://www.google.com"); String homePageString = homePage.asXml(); 
+1
source

Source: https://habr.com/ru/post/1299664/


All Articles