java - Java 中的 ServicePointManager 等价物

标签 java android vb.net ssl servicepointmanager

我正在尝试将 VB.net 项目转换为用于 Android 应用程序的 Java。我在某个时候卡住了。 我的 VB.net 代码是

Public Function SendWebRequest(ByVal url As String, ByVal postData As String, ByVal TimeOut As String, ByVal Code As String) As String
    Dim result As String
    Try


        postData = "Some String" + postData


        Dim webRequest As WebRequest = webRequest.Create(url)
        webRequest.Method = "POST"
        webRequest.Timeout = IntegerType.FromString(TimeOut)
        webRequest.Headers.Add(name1, value1)

         'problem is here
        ServicePointManager.Expect100Continue = True
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3

        Dim bytes As Byte() = System.Text.Encoding.UTF8().GetBytes(postData) 'Encoding.get_UTF8().GetBytes(postData)
        webRequest.ContentType = "application/x-www-form-urlencoded"
        webRequest.ContentLength = CLng(bytes.Length()) 'CLng(bytes.get_Length())
        Dim stream As Stream = webRequest.GetRequestStream()
        'stream.Write(bytes, 0, bytes.get_Length())
        stream.Write(bytes, 0, bytes.Length())
        stream.Close()
        Dim response As WebResponse = webRequest.GetResponse()
        stream = response.GetResponseStream()
        Dim streamReader As StreamReader = New StreamReader(stream)
        Dim text As String = streamReader.ReadToEnd()
        streamReader.Close()
        stream.Close()
        response.Close()
        result = text
    Catch expr_1AA As Exception
        Dim ex As Exception = expr_1AA
        Console.WriteLine("Exception ReadSecConn:" + ex.Message())
    End Try
    Return result
End Function

此代码发送网络请求。我已经使用 json 成功地将 web 请求从我的 android 应用程序发送到 web 服务器。除了这两行,所有部分都清楚

 ServicePointManager.Expect100Continue = True
 ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3

有谁知道它在 java 中的等价物,您的帮助将不胜感激 提前致谢

最佳答案

经过大量搜索和学习后,我得出结论,没有直接等同于 ServicePointManager.Expect100Continue = True ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 但是要将安全协议(protocol)设置为 SSL3,我们可以使用

System.setProperty("https.protocols", "SSLv3");

希望对你有帮助

关于java - Java 中的 ServicePointManager 等价物,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24646384/

相关文章:

java - 如何使用 Base 64 调用 ocr.space API

android - 可观察的 startWith 未在 doOnNext 中发出

vb.net - 如何在 RichTextBox 中隐藏插入符号?

python - 为什么对浮点的简单数学运算会在 VB.Net 和 Python 中返回意外(不准确)的结果?

java - 安装 WAS 8.5 插件后 Eclipse 市场无法运行

java - JSTL 调用一个不是 setter 或 getter 的方法

JAVA 读取数值数据并存储到数组列表

android - ExpandableListView 占据父 View 的所有宽度。安卓

android - 新的动态功能模块和热插拔

vb.net - Resharper 代码检查错误?