我正在开发一个java代理来监视我的应用服务器中发生的http通信.我想知道传出Https连接中使用的SSL版本(SSLv3,TLS等).有办法以任何方式获得SSL版本吗?
我在HttpsUrlConnection上使用'get'方法.当我在eclipse(Windows)上测试我的代码时,它运行正常.当我将它压缩到jar文件并在android studio上使用它时,它给了我'405 - 方法不允许'.这是什么意思,我用不好的动词(预期的GET)运行方法.
这是我设置http方法类型的方式:
conn.setRequestMethod("GET");
Run Code Online (Sandbox Code Playgroud)
我将http方法设置为'get',当我调试它时 - conn.getRequestMethod = GET和conn.delegate.getRequestMethod = POST.
错误响应是 - {"消息":"请求的资源不支持http方法'POST'."}
已编辑 - 已添加代码:
public static HttpsURLConnection getClient(URL url, LoginToken securityToken, RequestMethod methodType, String requestFormat, String responseFormat) throws IOException, SecurityTokenException {
HttpsURLConnection conn = (HttpsURLConnection)url.openConnection();
conn.addRequestProperty("Accept-Charset", "UTF-8");
conn.addRequestProperty("Content-Type", requestFormat);
conn.addRequestProperty("Accept", responseFormat);
conn.addRequestProperty("User-Agent", "***SDK/1.0");
conn.setRequestProperty("Cache-Control", "no-cache");
if(securityToken != null) {
LoginToken.ValidateToken(securityToken);
conn.addRequestProperty("Authorization", String.format("Bearer %1$s", new Object[]{securityToken.getTemporarySecurityCode()}));
}
conn.setRequestMethod(methodType.toString());
conn.setUseCaches(false);
conn.setDoOutput(true);
return conn;
}
public Boolean IsCompleted() throws SecurityTokenException, CommandFailedException {
LoginToken.ValidateToken(this.getSecurityToken());
HttpsURLConnection conn = null;
Gson …Run Code Online (Sandbox Code Playgroud) 不推荐使用DefaultHttpClient,ThreadSafeClientConnManager,HttpParams,HttpProtocolParams,SchemeRegistry,SSLSocketFactory,NameValuePair,HttpResponse.
我试图使用HttpsUrlConnection,但我对它们感到困惑.
protected Gson gson;
private ThreadSafeClientConnManager threadSafeClientConnManager;
private DefaultHttpClient client;
AbstractServiceApi() {
// sets up parameters
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, ENCODING);
HttpConnectionParams.setConnectionTimeout(params, 95 * 1000);
HttpConnectionParams.setSoTimeout(params, 95 * 1000);
HttpConnectionParams.setStaleCheckingEnabled(params, false);
params.setBooleanParameter("http.protocol.expect-continue", false);
// registers schemes for both http and https
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory();
sslSocketFactory.setHostnameVerifier(SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
registry.register(new Scheme("https", sslSocketFactory, 443));
threadSafeClientConnManager = new ThreadSafeClientConnManager(params, registry);
client = new DefaultHttpClient(threadSafeClientConnManager, params);
gson = new Gson();
}
Run Code Online (Sandbox Code Playgroud)
我没有密钥库. …
我正在尝试使用签名URL将视频文件上传到云存储.HTTP put方法用于上传.当我尝试使用"HttpsUrl`连接"进行连接时,它会返回一些错误,如javax.net.ssl.SSLHandshakeException:握手失败.我该如何解决这个问题?这是我的代码:
URL url = new URL(url_string);
httpsUrlConnection = (HttpsURLConnection) url.openConnection();
httpsUrlConnection.setDoOutput(true);
httpsUrlConnection.setDoInput(true);
httpsUrlConnection.setRequestMethod(requestMethod);
httpsUrlConnection.setRequestProperty("Content-Type", "application/json");
httpsUrlConnection.setRequestProperty("Accept", "application/json");
httpsUrlConnection.connect();
Run Code Online (Sandbox Code Playgroud)
stacktrace就是这样的
javax.net.ssl.SSLHandshakeException: Handshake failed
com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:390c)
com.android.okhttp.Connection.upgradeToTls(Connection.java:201)
Run Code Online (Sandbox Code Playgroud) ssl android google-cloud-storage httpsurlconnection pre-signed-url