本文介绍了cURL在Java中等效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有
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
);
我必须通过java。你能帮我吗?
I have to do it via java. Can you help me?
感谢Jakub
推荐答案
HttpClient方法:
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;
如此:
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());
编辑:糟糕。 StringEscapeUtils来自commons-lang。
Oops. StringEscapeUtils comes from commons-lang. http://commons.apache.org/lang/api/org/apache/commons/lang/StringEscapeUtils.html
这篇关于cURL在Java中等效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!