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リクエストを正常に送信しました。この2行以外はクリアです
ServicePointManager.Expect100Continue = True
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3
Javaで同等のものを知っている人はいますか?事前に感謝します。