B4J Question libcurl library

Sandman

Expert
Licensed User
Longtime User
Sorry, I don't have the skills to do that, but I do have a question. (And mind you, I'm a big fan of curl.)

Why? In what way would it make a difference for you to get curl into B4J?
 
Upvote 0

Tim Chapman

Active Member
Licensed User
Longtime User
Upvote 0

Sandman

Expert
Licensed User
Longtime User
Understood. In that case, this Wish might be something for you.
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
A few years ago I commented on this conversion from curl to b4x. I was working on the topic at the time and resumed the development I had for conversion or code generator CURL to B4X.

B4X:
Public Sub TestGenerateCodeFromCurl
    Dim CurlText As String = $"curl -X GET \"https://api.example.com/submit\""$
    Log(GenerateCodeFromCurl(CurlText))
    Log("-------------------")
    Dim CurlText As String = $"curl -X GET \"https://api.example.com/submit\" -d '{\"key1\":\"value1\"}' -H \"Content-Type: application/json\""$
    Log(GenerateCodeFromCurl(CurlText))
    Log("-------------------")
    Dim CurlText As String = $"curl -X POST \"https://api.example.com/submit\" -d '{\"key1\":\"value1\"}' -H \"Content-Type: application/json\""$
    Log(GenerateCodeFromCurl(CurlText))
    Log("-------------------")
    Dim CurlText As String = $"curl -X PUT \"https://api.example.com/submit\" -d '{\"key1\":\"value1\"}' -H \"Content-Type: application/json\""$
    Log(GenerateCodeFromCurl(CurlText))
End Sub

Ouput:
B4X:
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
curl -X GET "https://api.example.com/submit"
Public Sub GETHttpRequest As String
        Dim Result As String
        Dim j As HttpJob
        Try
                j.Initialize("", Me)
                j.Download2("https://api.example.com/submit", Null)
                Wait For (j) JobDone(j As HttpJob)
                If j.Success Then
                        Result = j.GetString
                End If
      Catch
                Log(LastException)
        End Try
        j.Release
        Return Result
End Sub
-------------------
curl -X GET "https://api.example.com/submit" -d '{"key1":"value1"}' -H "Content-Type: application/json"
Public Sub GETHttpRequest As String
        Dim Result As String
        Dim j As HttpJob
        Try
                j.Initialize("", Me)
                j.Download2("https://api.example.com/submit", {"key1":"value1"})
                j.GetRequest.SetHeader("Content-Type","application/json"
                Wait For (j) JobDone(j As HttpJob)
                If j.Success Then
                        Result = j.GetString
                End If
      Catch
                Log(LastException)
        End Try
        j.Release
        Return Result
End Sub
-------------------
curl -X POST "https://api.example.com/submit" -d '{"key1":"value1"}' -H "Content-Type: application/json"
Public Sub POSTHttpRequest As String
        Dim Result As String
        Dim j As HttpJob
        Try
                j.Initialize("", Me)
                j.PostString("https://api.example.com/submit",{"key1":"value1"})
                j.GetRequest.SetHeader("Content-Type","application/json"
                Wait For (j) JobDone(j As HttpJob)
                If j.Success Then
                        Result = j.GetString
                End If
      Catch
                Log(LastException)
        End Try
        j.Release
        Return Result
End Sub
-------------------
curl -X PUT "https://api.example.com/submit" -d '{"key1":"value1"}' -H "Content-Type: application/json"
Public Sub PUTHttpRequest As String
        Dim Result As String
        Dim j As HttpJob
        Try
                j.Initialize("", Me)
                j.PutString("https://api.example.com/submit",{"key1":"value1"})
                j.GetRequest.SetHeader("Content-Type","application/json"
                Wait For (j) JobDone(j As HttpJob)
                If j.Success Then
                        Result = j.GetString
                End If
      Catch
                Log(LastException)
        End Try
        j.Release
        Return Result
End Sub
 
Upvote 0
Top