javax.net.ssl.HttpsURLConnection
的默认请求方法是什么?
如果我未明确指定任何方法类型,则默认为 GET
还是 POST
?
以下代码中使用哪种方法类型- GET?
或 POST?
protected URLConnection createUrlConnection(URL url) throws IOException,
GeneralSecurityException, LinkKeyStoreException
{
URLConnection urlConnection = url.openConnection();
if (urlConnection instanceof HttpsURLConnection)
{
((HttpsURLConnection) urlConnection).setHostnameVerifier(Constants.ACCEPT_ALL_HOSTS);
((HttpsURLConnection) urlConnection).setSSLSocketFactory(createSSLSocketFactory());
}
urlConnection.setConnectTimeout(Constants.URL_CONNECT_TIMEOUT);
urlConnection.setReadTimeout(Constants.URL_READ_TIMEOUT);
urlConnection.setRequestProperty("Range", "bytes=" + totalBytesDownloaded + "-");
urlConnection.connect();
return urlConnection;
}
答案 0 :(得分:1)
默认方法为GET
,而HttpUrlConnection#setRequestMethod
的{{3}}提示:
设置URL请求的方法,其中一种: 得到 开机自检 头 选件 放 删除 跟踪 是合法的,受协议限制。 默认方法为GET。
答案 1 :(得分:0)
HttpURLConnection默认使用GET方法。