Subject Re: Post JSon Data
From Andreas Gehrs-Pahl <Andreas@AbsoluteSoftwareLLC.com>
Date Sun, 19 Jan 2020 16:46:36 -0500
Newsgroups xb2net

Robert,

It doesn't look like there is anything wrong with the Xb2Net request.

>Connection: Keep-Alive
>Connection: Close

If you want to change this, add this to your code:
oHttp:KeepAlive(.t.)

>Content-Type: application/x-www-form-urlencoded;charset=UTF-8
>Content-Type: application/x-www-form-urlencoded

To change the Mime Type, add this to your code:
oForm:MimeType := "application/x-www-form-urlencoded;charset=UTF-8"

>User-Agent: Mozilla/4.0(compatible;MSIE6.0;Windows NT 5.0)
>User-Agent: Xb2.NET/3.6.02.355

To change the User-Agent Header, you can add it explicitly when calling
the oHTTP:Execute() method. The same is true for the "Content-Type" Header,
if you don't make the "oForm" object your Content.

>pass=12345678&person={"id":"p1","name":"test","idcardNum":"111111"}
>pass=12345678&person=%7B%22id%22%3A%22p2%22%2C%22name%22%3A%22test2%22%2C%22idcardnum%22%3A%22222222%22%7D

This is basically the same text, even though the actual values are different
in the second (Xb2Net) text line as per your code. Also the second line is
URL-encoded, replacing the characters {":,} with their %Hex Escape Codes.

>? oJ:AsString()
>it output  
>{"id"="p2","name":"test2t","idcardNum":"222222"}

The "=" in the output is actually a ":", but otherwise, your code looks
fine.

If you don't want to have the form data URL-encoded (escaped) (and also the
other headers updated), you can do this instead:

oHttp:KeepAlive(.t.)
oResponse := oHttp:Execute("http://" + cServerIp + "/AIPersonCreate", ;
          "POST", XbUnEscape(oForm:AsString()), {{"Content-Type", ;
          "application/x-www-form-urlencoded;charset=UTF-8"}, ;
          {"User-Agent", "Mozilla/4.0(compatible;MSIE6.0;Windows NT 5.0)"}})

That should give you pretty much the same result as in your first option.

Hope that helps,

Andreas
--
Andreas Gehrs-Pahl
Absolute Software, LLC

phone: (989) 723-9927
email: Andreas@AbsoluteSoftwareLLC.com
web:   http://www.AbsoluteSoftwareLLC.com
[F]:   https://www.facebook.com/AbsoluteSoftwareLLC

Recent messages in this thread
 
-# Post JSon Data Robert Tin 19-Jan-2020 08:08 am
.\# Re: Post JSon Data (Current message) Andreas Gehrs-Pahl 19-Jan-2020 04:46 pm