How to open a default Windows browser and send HTTP message data to an open address in a browser in WinForm?

I want to open the application URL in the default browser in a WinForm application. And then send some data as an HTTP POST method, not as a query string. Now the problem is that I want to open the URL in the default browser that I used this code:

Process.Start("http://www.ketabchin.com/sort)

But in this command, I cannot send message data to this URL. Then I used this code:

Public Shared Function PostMessageToURL(url As String) As String
    Dim request As WebRequest = WebRequest.Create("https://www.ketabchin.com/windows-logged")
    request.Method = "POST"
    Dim postData As String = "u=" & FrmMain.Username & "&p=" & FrmMain.Password & "&url=" & url
    Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData)
    request.ContentType = "application/x-www-form-urlencoded"
    request.ContentLength = byteArray.Length
    Dim dataStream As Stream = request.GetRequestStream()
    dataStream.Write(byteArray, 0, byteArray.Length)
    dataStream.Close()
    Dim response As WebResponse = request.GetResponse()
    Console.WriteLine(CType(response, HttpWebResponse).StatusDescription)
    dataStream = response.GetResponseStream()
    Dim reader As New StreamReader(dataStream)
    Dim responseFromServer As String = reader.ReadToEnd()

    reader.Close()
    dataStream.Close()
    response.Close()
    Return responseFromServer
End Function

HTTP POST url, - . ? . WinForm, "goto website" buttton . , .

+4
1

, , , . , , AppForm -, VB ( , IE/Edge, IE/FF/Chrome). , , , :

, , IP-, .

+1

Source: https://habr.com/ru/post/1649998/


All Articles