4

I Want to my Application Open URL in default browser in WinForm Application. And Then Send Some data as HTTP POST method not as query string. now the problem is if i want to open URL in default browser i used this code:

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

But in this command i can not send post data to that 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

This one Send the HTTP POST request data to url but i can not open it or the response in default web browser. how can i do this? The logic of behind this action is. i have a WinForm Application and when my user click on "goto website" buttton in my application . i want to open the browser and send logging data to the login page, so the user can visit the site in Logging mode.

Amin AmiriDarban
  • 2,031
  • 4
  • 24
  • 32

1 Answers1

1

I don't know if your problem still needs a solution, but I use you code to make an alternative to a similar issue. I have the same request, I need a user to click on an AppForm button to login a web site, but I didn't found any way to send post data from VB app to a navigator (may be one solution could exists with IE/Edge but my users can use IE/FF/Chrome). So here are the steps I made to find a solution:

  1. The button where user has to click to connect is using your code
  2. The postData contains all data that the web site needs to identify the user (like a user name and a password) + IP address
  3. The website checks these data and if everything is okay it's generating a unique 32bit key and store it in database
  4. Then web site send a json response {"status" => "ok", "token" => $key, "ip" => $ipFromPostRequest}
  5. VB app is now opening a programm (you can find some code to open a link with default browser and if not defined IE or FF) with a link like http://www.website.com/auto-login/32-BITS-GENERATED-KEY
  6. Web site checks in database if Key and IP corresponds
  7. Web site creates a session and redirect user to home and delete Key from database

I think it's not the best solution for security reasons, but on my side this is a compagny network with unique computer names and internal IP address and this procedure is working.

J. Grunder
  • 143
  • 2
  • 13