Android Question HTTPJob.poststring does not work?

grafsoft

Well-Known Member
Licensed User
Longtime User
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;
 

DonManfred

Expert
Licensed User
Longtime User
Basis.MapToJSON (amap,True)
you are creating a json here. the payload will hold the json.
There is NO data in $_REQUEST as you are not sending a postrequest with values...
B4X:
    Dim job As HttpJob
    job.Initialize("job",Me)
    job.PostString("URL","string")
Copare to your code... You are using "P" as url. That´s wrong...

You need to get the poststring payload in php with
PHP:
$jsonstring = file_get_contents("php://input");

You can not use Poststring AND Download in one call. Remove the downloadcall
 
Last edited:
Upvote 0

grafsoft

Well-Known Member
Licensed User
Longtime User
Thank you, always a pleasure to hear from you.

I do not understand file_get_contents("php://input");

With this, I get an internal server error.
 
Upvote 0
Top