我正试图将一个VB.net项目转换为一个Androidapp.i的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此代码发送一个web请求。我已经使用json成功地将我的android应用程序的web请求发送到web服务器。除这两行外,所有部分都是清楚的。
ServicePointManager.Expect100Continue = True
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3有谁知道它在java中的等价物吗?您的帮助是非常感谢的。
发布于 2014-07-16 12:32:35
经过大量的搜索和学习,我得出的结论是,除了将ServicePointManager.Expect100Continue = True ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3安全协议设置为SSL3之外,没有直接等效的SSL3协议,我们可以使用
System.setProperty("https.protocols", "SSLv3");希望这能帮到你
https://stackoverflow.com/questions/24646384
复制相似问题