我正在尝试将 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
此代码发送 Web 请求。我已经使用 json 成功地将我的 android 应用程序的 web 请求发送到 web 服务器。除了这两行之外,所有部分都清楚
ServicePointManager.Expect100Continue = True
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3
有没有人知道它在java中的等价物,您的帮助将不胜感激