iOS Question upload with json to a server

Ju Yang

Active Member
Licensed User
Longtime User
when i send a string of json to a server,it shows 400 error
B4X:
Sub Button1_Click
   dim a as map
    a.Initialize
    a.Put("username","hilee")
    a.Put("password","123456")
    a.Put("email","1316792450@qq.com")
    a.Put("nickname","kk")
    a.Put("firstname","wang")
    a.Put("lastname","uu")
    a.Put("photo","http://www.freetalk.com/photo/12345")

    Dim jssonp As JSONGenerator
    jssonp.Initialize(a)
    sname=jssonp.ToString
    Log(sname)
    Dim b As HttpRequest
    File.Copy(File.DirAssets,"smiley.png", File.DirDocuments, "smiley.png")

    b.InitializePost2("http://58.246.1.146:16040/users",sname.GetBytes("UTF8"))

    b.SetContentType("application/json")
    Dim h As HttpClient
    h.Initialize("h")
    h.Execute(b,1)
    Log("click")
End Sub

Sub h_ResponseSucce (Response As HttpResponse, TaskId As Int)
    Log("response success")

End Sub
Sub h_ResponseError (Response As HttpResponse, Reason As String, StatusCode As Int, TaskId As Int)
Log(Response.GetString)
    Log("Error response: " & Response.GetString & ", status code: " & StatusCode)

End Sub
my server api type :
{
"username": "",
"password": "123456",
"email": "1316792450@qq.com",
"nickname": "kk",
"firstname": "123",
"lastname": "5657"
}
the error :
Error response: , status code: 400
 
Last edited:

Ju Yang

Active Member
Licensed User
Longtime User
yet,i also use iHttpUtils2,it does not work ,however ,when i post like this b.InitializePost2( "http://www.b4x.com/print.php", "first key=first value&key2=value2".GetBytes("UTF8")),it is fine
can you tell me why?
thank you
 
Upvote 0
Top