[solved]
Hello,
i have a client app at phone (b4a) and a web server with iis and a vs studio 2017 web api project.
i will post data as json to server (i used okhttputils2) and the server should deserialize the data into a object/class.
but i facing the problem that nothing is deserialized and the class/object is empty there
i made a html page with form post and this works fine (today but not now^^)!?
the code in web api looks like this
it ouput something like this, so i thought i can put the same in ..
here i have the problem that data propertys are empty when i send a json via post from b4a app
i am not sure
this html form works but i will using a app
(just a example not the real one)
this is the sending part in b4a app
Hello,
i have a client app at phone (b4a) and a web server with iis and a vs studio 2017 web api project.
i will post data as json to server (i used okhttputils2) and the server should deserialize the data into a object/class.
but i facing the problem that nothing is deserialized and the class/object is empty there
i made a html page with form post and this works fine (today but not now^^)!?
the code in web api looks like this
B4X:
MyClass Template()
{
return new (MyClass)
}
it ouput something like this, so i thought i can put the same in ..
{"FailureId":0,"FailureDateTime":"2018-03-20T19:19:27.4971098+01:00","CompanyId":0,"UserId":0,"UserName":null,"Location":null,"Trouble":null,"Note":null,"GPS_LATITUDE_DEGREE":0.0,"GPS_LONGITUDE_DEGREE":0.0,"GPS_ALTITUDE_METER":0.0}
here i have the problem that data propertys are empty when i send a json via post from b4a app
B4X:
SaveData(MyClass data)
{
//...
}
i am not sure
(just a example not the real one)
B4X:
<html>
<body>
<form action="https://user:password@domain/myfunction/" method="Post">
Datum:<br>
<input name="FailureDateTime" type="text" value="03-20-2018 15:01">
<input name="UserName" type="text" value="Markus">
<input name="Location" type="text" value="Mülheim">
<input name="Trouble" type="text" value="Drucker">
<input name="Note" type="text" value="Note">
<input type="submit" value="Submit">
</form>
</body>
</html>
this is the sending part in b4a app
B4X:
Sub Send() As Boolean
Dim D As String
DateTime.DateFormat = "dd/MM/yyyy"
DateTime.TimeFormat = "HH:mm:ss"
D = DateTime.Date(DateTime.Now) & "T" & DateTime.Time(DateTime.Now)
Dim Map1 As Map
Map1.Initialize
Map1.Clear
Map1.Put("FailureId",0)
Map1.Put("FailureDateTime",D)
Map1.Put("CompanyId",0)
Map1.Put("UserId",0)
Map1.Put("UserName",EditTextUserName.Text)
Map1.Put("Trouble",EditTextTrouble.Text)
Map1.Put("Note",EditTextNote.Text)
Map1.Put("Location",EditTextLocation.Text)
Map1.Put("GPS_ALTITUDE_METER",0.0)
Map1.Put("GPS_LATITUDE_DEGREE",0.0)
Map1.Put("GPS_LONGITUDE_DEGREE",0.0)
'------------ Prüfen
If Map1.Get("UserName")="" Then
ToastMessageShow("Name eingeben ..",False)
Return False
End If
If Map1.Get("Trouble")="" Then
ToastMessageShow("Problem eingeben ..",False)
Return False
End If
If Map1.Get("Location")="" Then
ToastMessageShow("Ort eingeben ..",False)
Return False
End If
'------------
Dim JSON As JSONGenerator
JSON.Initialize(Map1)
Dim data As String = JSON.ToPrettyString(1) ' JSON.ToString()
Log(data)
Dim Job As HttpJob
Job.Initialize("Job1",Me)
Job.Username="..."
Job.Password="..."
Job.PostString("https://domain/myfunction" , data )
Return True
End Sub
Sub JobDone (Job As HttpJob)
Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
If Job.Success = True Then
Select Job.JobName
Case "Job1"
Log(Job.GetString)
If Job.GetString.StartsWith(Chr(34) & "OK" & Chr(34) ) Then 'das ist ja mal Panne^^
ToastMessageShow(Job.GetString,True)
StartActivity(ActivityThanks)
Activity.Finish
Else
ButtonSend.Enabled=True
ToastMessageShow("Error: " & Job.GetString, True)
End If
Case "JobTemplate"
Log(Job.GetString)
End Select
Else
ButtonSend.Enabled=True
Log("Error: " & Job.ErrorMessage)
ToastMessageShow("Error: " & Job.ErrorMessage, True)
End If
Job.Release
End Sub
Last edited: