I send a big JSON with a httprequest to the Server. The php-script on the server says the string is empty. What am I doing wrong?
B4X:
Sub MapToJSON(sm As Map, bEnclose As Boolean) As String
' convert a map to a json string
Dim iCnt As Int
Dim iTot As Int
Dim sb As StringBuilder
sb.Initialize
If bEnclose = True Then sb.Append("{")
' get size of map
iTot = sm.Size - 1
iCnt = 0
For Each mKey As String In sm.Keys
Dim mValue As String = sm.Get(mKey)
sb.Append(QUOTE).Append(mKey).Append(QUOTE).Append(":").Append(QUOTE)
sb.Append(mValue).Append(QUOTE)
If iCnt < iTot Then sb.Append(",")
iCnt = iCnt + 1
Next
If bEnclose = True Then sb.Append("}")
Return sb.ToString
End Sub
Dim werjob As HttpJob
werjob.initialize ("wer",Me)
Dim amap As Map
amap.Initialize
amap.Put ("count",wercr.RowCount)
' all my phone contacts, a few hundred
For wercount=0 To wercr.RowCount-1
wercr.Position=wercount
werphone=wercr.Getstring ("number")
Log (werphone)
werphone=werphone.Replace ("+","")
werphone=werphone.Replace (" ","")
werid=wercr.Getstring ("AID")
amap.put ("AID" & wercount,werid)
amap.put ("phone" & wercount,werphone)
Next
werjob.PostString ("p",Basis.MapToJSON (amap,True))
werjob.Download (t)
...
' my php code
function request ($s)
{
if (isset($_REQUEST[$s]))
{
return ($_REQUEST[$s]);
}
else
{
return ("");
}
}
function sqlrequest($s)
{
return mysql_real_escape_string (request($s));
}
$p=sqlrequest("p");
$arr=json_decode ($p,true);
echo var_dump ($p);
$count=$arr ["count"];
echo $count;