Italian Aggiungere testo in una textarea online tramite metodo POST

Mattiaf

Active Member
Licensed User
Ciao a tutti, vorrei aggiungere del testo in una TextArea in maniera tale da tenerla sempre aggiornata.
In vb.net ci sono riuscito con questo codice
B4X:
 Private Function RandomCookie() As String
        Dim rnd(19) As Byte
        Dim r = New Random()
        r.NextBytes(rnd)
        Return BitConverter.ToString(rnd).Replace("-", "").ToLower()
    End Function
    Private Function SaveData(ByVal data As String, ByVal urlKey As String, ByVal padKey As String) As Boolean
        Const url As String = "https://notepad.pw/save"
        Dim postData As New Specialized.NameValueCollection()
        postData.Add("key", padKey)
        postData.Add("pad", data)
        postData.Add("url", urlKey)
        postData.Add("pw", "")
        postData.Add("monospace", "0")
        postData.Add("caret", "0")

        Try
            Dim wc As New WebClient()
            wc.Encoding = Text.Encoding.UTF8
            wc.Headers.Add(HttpRequestHeader.Cookie, "pad_cookie=" + RandomCookie())
            wc.Headers.Add("X-Requested-With", "XMLHttpRequest")
            wc.UploadValuesAsync(New Uri(url), postData)
            Return True
        Catch ex As Exception
            MsgBox("Error: " & ex.Message)
            Return False
        End Try
    End Function

    Sub Main()
        ' Esempio di uso:
        Dim testo As String = "text text text"
        Dim ok As Boolean = SaveData(testo, "011hk762", "63958th7q")
        If ok Then
            MsgBox("OK!")
        End If
    End Sub

Anche se questa funzione in realtà cambia il testo della TextArea, per cui non va ad aggiungere nulla..

Come posso convertire il tutto in b4a? Ho provato le varie librerie tipo okhttputils2 ma non riesco ad implementarla..
Inoltre, per uno strano motivo voluto dagli sviluppatori di quel sito, c'è bisogno di usare quel random cookie e quell header custom al fine di fare in modo che la textarea salvi il suo contenuto..
Apprezzo qualsiasi aiuto.
Buona serata
 
Top