iOS Question PutString

futurec

Member
Licensed User
hi
i send data putstring with postman run successful but run in b4i v7.5 don't send data
please help
send by this code:
    Dim j As HttpJob
    j.Initialize("",Me)
    Dim str As String = "http://194.5.205.91:3333/api/v1/client/user/info"
    Dim str1 As String = $"birthdate=${txtBirthDate.Text}&email=${txtEmail.Text}&fullname=${txtName.Text}&tel=${txtTel.Text}&nationalcode=123456&mobile=${txtMobile.Text}"$
    Log(str1)
    j.PutString(str,str1)
    j.GetRequest.SetHeader("authorization",Public_mdl.Token)
    Wait For (j) jobdone (j As HttpJob)
    hud.ProgressDialogHide
    If j.Success Then
        Dim str As String = j.GetString
        Log(str)
        nav.RemoveCurrentPage
    Else
        Log(j.ErrorMessage)
    End If

return
{"code":"422","error":true,"message":"خطا در اعتبار سنجی","data":[{"message":"required validation failed on email","field":"email","validation":"required"}]}

on postman
Capture.PNG
 
Last edited:

futurec

Member
Licensed User
yes
There was no result
Other things work fine like
Poststring and download
but putstring don't send data to server
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
The data is sent, the return message from the server
{"code":"422","error":true,"message":"خطا در اعتبار سنجی","data":[{"message":"required validation failed on email","field":"email","validation":"required"}]}
seems to have some problem recognizing the email field correctly.
Did you check them ?
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Please note that PutString will send the information in str1 to the server in the body of the message, not the URL. The postman screenshot you are providing shows that postman is including all your parameters in the URL (right after the ?). Please note that the way your are building str1, it will not be URL encoded and may not be properly accepted by your server. Try the following:

B4X:
   Dim j As HttpJob
    j.Initialize("",Me)
    Dim str As String = "http://194.5.205.91:3333/api/v1/client/user/info"
    'Dim str1 As String = $"birthdate=${txtBirthDate.Text}&email=${txtEmail.Text}&fullname=${txtName.Text}&tel=${txtTel.Text}&nationalcode=123456&mobile=${txtMobile.Text}"$
    Dim urlInfo as Map = CreateMap("birthdate" : txtBirthDate.Text, "email" : txtEmail.Text, "fullname" : txtName.Text, "tel" : txtTel.Text, "nationalcode" : "123456", "mobile" : txtMobile.Text)
    Log($"${str}?${UrlEncodeMap(urlInfo)}"$) ' This should give you an idea of what the URL looks like for the PUT call
    j.PutString($"${str}?${UrlEncodeMap(urlInfo)}"$,"")
    j.GetRequest.SetHeader("authorization",Public_mdl.Token)
    Wait For (j) jobdone (j As HttpJob)
    hud.ProgressDialogHide
    If j.Success Then
        Dim str As String = j.GetString
        Log(str)
        nav.RemoveCurrentPage
    Else
        Log(j.ErrorMessage)
    End If
Note 1: Untested code
Note 2: UrlEncodeMap can be found here: https://www.b4x.com/android/forum/threads/b4x-urlencodemap.118626/
 
Upvote 0
Top