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;
}
最佳答案
默认方法是GET
,Javadoc对于 HttpUrlConnection#setRequestMethod
提示:
Set the method for the URL request, one of: GET POST HEAD OPTIONS PUT DELETE TRACE are legal, subject to protocol restrictions. The default method is GET.
关于java - HttpsURLConnection默认请求方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55036664/