JSON, URL-encode, and UTF-8

Peter W A Wood peterwawood at gmail.com
Thu Aug 20 23:51:54 EDT 2015


Jacque

> On 21 Aug 2015, at 11:32, J. Landman Gay <jacque at hyperactivesw.com> wrote:
> 
> I'd thought of that too. I'll ask the PHP guy to set up an http URL.

I don’t think it is a problem with HTTPS. With Google and Stack overflow’s help, I found this website - http://httpbin.org - you can send a POST request to https://httpbin.org/post and it will return the POST data to you (in JSON). I ran your test against both the http:// and https:// URLs and both worked.

> The other difference is the UTF8 encoding, but it's my understanding that servers always expect to receive that.

I don’t think that all servers expect to receive UTF-8. The character encoding can be specified in configuration files.

> Thanks very much to you and Charles for your tests. I agree with Charles that it may indicate there is something wrong with the PHP script. If I give him the simple echo script that you posted here, is that a good test?

It is possible but this may be more useful:

PHP:
<?php 
  var_dump($_POST);
?>

It will return the POST data received by PHP. For example:

LiveCode Message Box:

put textEncode("{ " & quote & "é" & quote & ": 1}", "UTF-8") into tJSON
put "json=" before tJSON
post tJSON to URL "http://localhost/jacque.php"
put textDecode(it, "UTF-8")

This is what it returns:
array(1) {
  ["json"]=>
  string(10) "{ "é": 1}"
}

Hope this helps.

Peter

PS I’m no PHP programmer.




More information about the Use-livecode mailing list