Java中的cURL等价
我有 在php中 我必须通过java来做。你能帮我吗Java中的cURL等价,java,curl,Java,Curl,我有 在php中 我必须通过java来做。你能帮我吗 谢谢Jakub看一看。孙有一些。它有各种支持某些特定HTTP和HTTPS功能的子类。我使用HttpClient方法: exec( "curl". " --cert $this->_cCertifikatZPKomunikace". " --cacert $this->_cCertifikatPortalCA". " --data \"request=".urlencode($fc_xml)."\"". " --
谢谢Jakub看一看。孙有一些。它有各种支持某些特定HTTP和HTTPS功能的子类。我使用HttpClient方法:
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
);
像这样:
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;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
编辑:哎呀。StringEscapeUtils来自commons-lang。除了Quotidian和Yacoby提供的纯Java答案之外,您还可以尝试在php中执行curl二进制文件。查看如何使用
ProcessBuilder
类。通过调用getRuntime()
链接到运行时的
一个不错的使用运行时的例子
使用运行时或ProcessBuilder的一个不错的示例
我希望其中有一些有用。cURL站点链接到Github上。您可以在Java中使用API
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());
像这样:
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;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
是的,但是它不是一个纯java的解决方案,这是java的主要优势是的,但这会使使用证书变得容易,而且会很好地从他最初的通话中转换过来dead@Thibault我已经在GitHub.HTTPClient上更新了绑定新位置的链接,这很好,但是您显示的代码可能会失败,因为它没有处理证书…我去了apache。httpcomponents已关闭,而不是您现在导入
org.apache.httpclient.*
。我下载了整个软件包,导入了它。它给了我大约100个错误。当我看到他们时,他们都在那个包裹的班级里。在下载的软件包commons
中找不到。其中的一些类试图导入org.apache.commons.
而没有commons文件夹!!!这是什么?这是一个很久以前回答过的问题。情况发生了变化,这不再是正确的方法。另一种选择: