URLConnection Equivalent to HTTPSSocket.SetFormData

  1. 3 months ago

    Jon O

    Mar 25 Pre-Release Testers, Xojo Pro Chicago Area USA

    I’m currently using an HTTPSSocket for posting and getting some data from a website. The first thing I have to do is log in to the site. In the HTTPSSocket, I set up a dictionary with my username and passwords. I then send that dictionary to the HTTPSSocket.SetFormData method. URLConnection has no such method for whatever reason.

    I have tried to figure out what that method actually creates so I can do it manually myself, but looking at the socket in the debugger, I can't actually find out what the SetFormData method does. Here’s what I send with the HTTPSSocket:

    Dim d As New Dictionary
    
    d.Value("Email") = somevalue
    d.Value("Password") = someothervalue
    
    HTTPsSock.SetFormData(d)
    Dim gcurl As String = kgcURLStart+"api/account/login"
    HTTPsSock.Post(gcurl)

    In URLConnection I only have the SetRequestContent method. I’m assuming I would do something like this in that method:

    Dim LoginText as string = “Email=somevalue&Password=someothervalue
    MyURLConnection.SetRequestContent(LoginText, ??????)
    MyURLConnection.Send(“POST”, kgcURLStart+"api/account/login”)

    The question marks, ????? in the SetRequestContent line are because I have no idea of the Mime Type to be used here. None of the documentation for either socket talks about that.

    What would I use?

    Thanks!

  2. Paul L

    Mar 25 Xojo Inc http://docs.xojo.com

    The 2nd code sample in the Sample Code section of the URLConnection.SetRequestContent page shows how to send form data and also shows that you'd use the Mime type of "application/x-www-form-urlencoded".

  3. Jon O

    Mar 25 Pre-Release Testers, Xojo Pro Chicago Area USA

    @Paul L The 2nd code sample in the Sample Code section of the URLConnection.SetRequestContent page shows how to send form data and also shows that you'd use the Mime type of "application/x-www-form-urlencoded".

    I thought that might be the case, but I wasn't absolutely positive on the Mime Type. And since there's no way to view the string that the HTTPSSocket.SetFormData method generates, I couldn't cross check and tell for sure.

  4. Jon O

    Mar 25 Pre-Release Testers, Xojo Pro Chicago Area USA

    @Paul L The 2nd code sample in the Sample Code section of the URLConnection.SetRequestContent page shows how to send form data and also shows that you'd use the Mime type of "application/x-www-form-urlencoded".

    And there's an error/bug in the Post Button action event. I just filed a bug report on it.

  5. Paul L

    Mar 25 Xojo Inc http://docs.xojo.com

    Thanks, Jon. I've fixed this for 2019r1.

  6. Jon O

    Mar 25 Pre-Release Testers, Xojo Pro Chicago Area USA

    Great, Paul. Thanks for the quick fix!

    And I have it working with the website I'm pulling data from. So all is good.

    The nice thing about the URLConnection object as opposed to the HTTPSSocket is that the URLConnection raises an error when there's no internet connection. The HTTPSSocket just sits there and does nothing.

or Sign Up to reply!