Re: JSON, URL-encode, and UTF-8

2015-08-21 Thread J. Landman Gay

On 8/21/2015 3:06 AM, Dave Cragg wrote:


Instead of removing the httpHeaders setting, what if you set it to
this?

set the httpHeaders to Content-Type:
application/x-www-form-urlencoded

This is normally the default for post, but if you had set it to
something else earlier, I was wondering whether the previous setting
was still being used.


So it turns out that was the answer. I'm very indebted to Charles for 
helping me, I never would have figured this out.


I had launched a new instance of LC 7.1 and it should have been using 
its default headers, so it seems that something has changed since 6.x. 
On the other hand, I did so much tinkering that application/json may 
have been retained from previous tests; I lost track.


--
Jacqueline Landman Gay | jac...@hyperactivesw.com
HyperActive Software   | http://www.hyperactivesw.com

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: JSON, URL-encode, and UTF-8

2015-08-21 Thread Peter W A Wood

 On 21 Aug 2015, at 10:59, Peter W A Wood peterwaw...@gmail.com wrote:
 
 Jacque
 
 On 21 Aug 2015, at 10:13, J. Landman Gay jac...@hyperactivesw.com 
 mailto:jac...@hyperactivesw.com wrote:
 
 Here's a test. This posts just fine in LC 6.x but fails in 7.0.6 and 7.1rc1.
 
 Make a field with this in it:
 
   [{Meals:Yes,Purpose:Business}]
 
 Now put this into a button or card script:
 
 constant kServerURL = https://www.domain.com/results.php 
 https://www.domain.com/results.php  --### use a valid URL here
 
 
 command sendToServer
  if the version  7 then
put fld 1 into tData
put json= before tData
  else
put textEncode(fld 1,UTF8) into tData
put textEncode(json=,UTF8) before tData
  end if
  post tData to kServerURL
  put it into tResponse
  put the result into tErr
  breakpoint -- so you can see it
 end sendToServer
 
 If someone can test this against a simple echo PHP maybe it will tell us 
 something. The real server returns empty in LC 7 and OK in LC 6.
 
 This works fine in LiveCode 7.0.3. I’ll download 7.1RC1 and see if it works 
 there too.
 
 Peter
 

It also works on LiveCode 7.1 RC1 … which took me hours to download :-(

Regards

Peter

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Re: JSON, URL-encode, and UTF-8

2015-08-21 Thread Dave Cragg

 On 21 Aug 2015, at 02:27, J. Landman Gay jac...@hyperactivesw.com wrote:
 
 On 8/20/2015 6:45 PM, Dave Cragg wrote:
 What happens if you remove the httpHeader setting and also UrlEncode
 tData?
 
 Still errors I'm afraid.

Instead of removing the httpHeaders setting, what if you set it to this?

set the httpHeaders to Content-Type:  application/x-www-form-urlencoded

This is normally the default for post, but if you had set it to something else 
earlier, I was wondering whether the previous setting was still being used.



___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: JSON, URL-encode, and UTF-8

2015-08-21 Thread Charles Warwick
HI Peter,

I did some testing with Jacque and found that her LC7 was sending the wrong 
content-type when posting to the PHP script.

In case anyone is interested:

It was using a content type of 'application/json’ which would have made sense 
if the PHP script was written to accept the json data directly.

However, it was expecting the POST data to be encoded in name/value format: 
variableA=valueAvariableB=valueB.

In this case, it required the json data stored in a variable called json:  i.e. 
 json=json data

Changing the headers as follows before the POST resolved the issue:

  set the httpHeaders to “content-type: application/x-www-form-urlencoded

As I mentioned to Jacque, the json data itself needs to be urlEncoded.

Cheers,

Charles

 On 21 Aug 2015, at 5:20 pm, Peter W A Wood peterwaw...@gmail.com wrote:
 
 
 On 21 Aug 2015, at 10:59, Peter W A Wood peterwaw...@gmail.com wrote:
 
 Jacque
 
 On 21 Aug 2015, at 10:13, J. Landman Gay jac...@hyperactivesw.com 
 mailto:jac...@hyperactivesw.com wrote:
 
 Here's a test. This posts just fine in LC 6.x but fails in 7.0.6 and 7.1rc1.
 
 Make a field with this in it:
 
  [{Meals:Yes,Purpose:Business}]
 
 Now put this into a button or card script:
 
 constant kServerURL = https://www.domain.com/results.php 
 https://www.domain.com/results.php  --### use a valid URL here
 
 
 command sendToServer
 if the version  7 then
   put fld 1 into tData
   put json= before tData
 else
   put textEncode(fld 1,UTF8) into tData
   put textEncode(json=,UTF8) before tData
 end if
 post tData to kServerURL
 put it into tResponse
 put the result into tErr
 breakpoint -- so you can see it
 end sendToServer
 
 If someone can test this against a simple echo PHP maybe it will tell us 
 something. The real server returns empty in LC 7 and OK in LC 6.
 
 This works fine in LiveCode 7.0.3. I’ll download 7.1RC1 and see if it works 
 there too.
 
 Peter
 
 
 It also works on LiveCode 7.1 RC1 … which took me hours to download :-(
 
 Regards
 
 Peter
 
 ___
 use-livecode mailing list
 use-livecode@lists.runrev.com
 Please visit this url to subscribe, unsubscribe and manage your subscription 
 preferences:
 http://lists.runrev.com/mailman/listinfo/use-livecode


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Re: JSON, URL-encode, and UTF-8

2015-08-21 Thread Peter W A Wood
Hi Charles

 On 21 Aug 2015, at 16:07, Charles Warwick char...@techstrategies.com.au 
 wrote:
 
 HI Peter,
 
 I did some testing with Jacque and found that her LC7 was sending the wrong 
 content-type when posting to the PHP script.
 
 In case anyone is interested:
 
 It was using a content type of 'application/json’ which would have made sense 
 if the PHP script was written to accept the json data directly.
 
 However, it was expecting the POST data to be encoded in name/value format: 
 variableA=valueAvariableB=valueB.
 
 In this case, it required the json data stored in a variable called json:  
 i.e.  json=json data
 
 Changing the headers as follows before the POST resolved the issue:
 
  set the httpHeaders to “content-type: application/x-www-form-urlencoded
 
 As I mentioned to Jacque, the json data itself needs to be urlEncoded.
 
 Cheers,
 
 Charles

Thanks for closing the loop. 

Cheers

Peter
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Re: JSON, URL-encode, and UTF-8

2015-08-20 Thread Charles Warwick
That script works here with HTTPS, I am guessing there is something else 
specific about the configuration.

 On 21 Aug 2015, at 1:23 pm, Peter W A Wood peterwaw...@gmail.com wrote:
 
 Jacque
 
 
 This works fine in LiveCode 7.0.3. I’ll download 7.1RC1 and see if it works 
 there too.
 
 Apart from the difference in LiveCode versions, there is one other difference 
 that may be significant. I am using HTTP on my machine not HTTPS. There have 
 been some bugs in LiveCode 7 HTTPS support. Is it possible for you to run 
 your test using HTTP to access your client’s server?
 
 Regards
 
 Peter
 
 ___
 use-livecode mailing list
 use-livecode@lists.runrev.com
 Please visit this url to subscribe, unsubscribe and manage your subscription 
 preferences:
 http://lists.runrev.com/mailman/listinfo/use-livecode


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Re: JSON, URL-encode, and UTF-8

2015-08-20 Thread J. Landman Gay
Now I don't know what to try next. :( But I appreciate your help. This 
is a weird one.


Is your PHP script like the one Peter posted?

On 8/20/2015 10:30 PM, Charles Warwick wrote:

That script works here with HTTPS, I am guessing there is something else 
specific about the configuration.


On 21 Aug 2015, at 1:23 pm, Peter W A Wood peterwaw...@gmail.com wrote:

Jacque



This works fine in LiveCode 7.0.3. I’ll download 7.1RC1 and see if it works 
there too.


Apart from the difference in LiveCode versions, there is one other difference 
that may be significant. I am using HTTP on my machine not HTTPS. There have 
been some bugs in LiveCode 7 HTTPS support. Is it possible for you to run your 
test using HTTP to access your client’s server?

Regards

Peter

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode



___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode




--
Jacqueline Landman Gay | jac...@hyperactivesw.com
HyperActive Software   | http://www.hyperactivesw.com


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Re: JSON, URL-encode, and UTF-8

2015-08-20 Thread J. Landman Gay

On 8/20/2015 10:23 PM, Peter W A Wood wrote:

Jacque



This works fine in LiveCode 7.0.3. I’ll download 7.1RC1 and see if
it works there too.


Apart from the difference in LiveCode versions, there is one other
difference that may be significant. I am using HTTP on my machine not
HTTPS. There have been some bugs in LiveCode 7 HTTPS support. Is it
possible for you to run your test using HTTP to access your client’s
server?


I'd thought of that too. I'll ask the PHP guy to set up an http URL. The 
other difference is the UTF8 encoding, but it's my understanding that 
servers always expect to receive that.


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?


--
Jacqueline Landman Gay | jac...@hyperactivesw.com
HyperActive Software   | http://www.hyperactivesw.com


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Re: JSON, URL-encode, and UTF-8

2015-08-20 Thread Peter W A Wood
Jacque

 On 21 Aug 2015, at 11:32, J. Landman Gay jac...@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.

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Re: JSON, URL-encode, and UTF-8

2015-08-20 Thread Peter W A Wood
Jacque

 
 This works fine in LiveCode 7.0.3. I’ll download 7.1RC1 and see if it works 
 there too.

Apart from the difference in LiveCode versions, there is one other difference 
that may be significant. I am using HTTP on my machine not HTTPS. There have 
been some bugs in LiveCode 7 HTTPS support. Is it possible for you to run your 
test using HTTP to access your client’s server?

Regards

Peter

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Re: JSON, URL-encode, and UTF-8

2015-08-20 Thread Monte Goulding

 On 21 Aug 2015, at 10:58 am, Peter W A Wood peterwaw...@gmail.com wrote:
 
 put textEncode({   quote  é  quote  : 1}, UTF-8) into tJSON
 put json= before tJSON
 post URLEncode(tJSON) to URL http://Localhost/jacque.php 
 http://localhost/jacque.php
 put textDecode(it, UTF-8”)

You would want to urlEncode tJSON before you put json= before it so the = isn’t 
encoded.

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Re: JSON, URL-encode, and UTF-8

2015-08-20 Thread Monte Goulding
Just before posting can you dump your tData variable into a binfile and send it 
to me. It's got to be something simple...

Sent from my iPhone

 On 21 Aug 2015, at 8:33 am, J. Landman Gay jac...@hyperactivesw.com wrote:
 
 Thanks, but still no go. I get the same errors.
 
 Is anyone posting from LC 7? I also just tried 7.1rc1 but it doesn't work 
 either.
 
 On 8/20/2015 5:04 PM, Monte Goulding wrote:
 Is your convertToJSON function returning UTF8? I’m not sure what LC 7 does 
 when it concatenates “json=“ to a UTF8 string. If for example that json= is 
 UTF16 and the rest of the data is UTF8 it’s not surprising the server is 
 freaking out. Try:
 
 put textEncode(“json=“,”UTF8”) before tData
 
 On 21 Aug 2015, at 7:53 am, J. Landman Gay jac...@hyperactivesw.com wrote:
 
 I'm still struggling with this. I have a valid JSON string, verified by a 
 web-checking site and by the PHP developer. He wants me to POST it this way:
 
 json=JSON string
 
 It doesn't work. He says the server receives it but it is not passed to the 
 PHP script because the main parameter is empty. Here's what I do:
 
  set the httpHeaders to content-type: application/json
  put convertToJSON() into tData -- produces valid JSON
  put json= before tData
  post tData to kServerURL
 
 The result is empty. The developer has set up the PHP to return the values 
 back to me for testing, but it is also always empty. He says this means 
 there is no main parameter, but he also said adding json= to the front 
 would provide that, he will just grab the params from what follows.
 
 The URL is https if that matters. I have also tried URLEncoding the JSON 
 but it didn't help. I also tried removing the custom header.
 
 He pointed me to this web site: https://www.hurl.it/ When I set it to 
 send JSON and enter the same params there, it POSTs successfully to the 
 server.
 
 How would you POST a JSON string to a PHP script on a secure server?
 
 --
 Jacqueline Landman Gay | jac...@hyperactivesw.com
 HyperActive Software   | http://www.hyperactivesw.com
 
 ___
 use-livecode mailing list
 use-livecode@lists.runrev.com
 Please visit this url to subscribe, unsubscribe and manage your 
 subscription preferences:
 http://lists.runrev.com/mailman/listinfo/use-livecode
 
 
 ___
 use-livecode mailing list
 use-livecode@lists.runrev.com
 Please visit this url to subscribe, unsubscribe and manage your subscription 
 preferences:
 http://lists.runrev.com/mailman/listinfo/use-livecode
 
 
 -- 
 Jacqueline Landman Gay | jac...@hyperactivesw.com
 HyperActive Software   | http://www.hyperactivesw.com
 
 
 ___
 use-livecode mailing list
 use-livecode@lists.runrev.com
 Please visit this url to subscribe, unsubscribe and manage your subscription 
 preferences:
 http://lists.runrev.com/mailman/listinfo/use-livecode

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Re: JSON, URL-encode, and UTF-8

2015-08-20 Thread Monte Goulding

 On 21 Aug 2015, at 9:25 am, Peter W A Wood peterwaw...@gmail.com wrote:
 
 You’re content is no longer valid JSON once you have inserted the “json=“ (at 
 the PHP developer’s request). There may be a conflict between the header and 
 the actual content. What happens if you remove the line setting the 
 httpHeaders?

That’s a good question. I can’t see anything wrong with the JSON itself after 
reviewing the file. Validates and formats fine in TextMate. Are you sure they 
want post and not get or put?
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Re: JSON, URL-encode, and UTF-8

2015-08-20 Thread J. Landman Gay

On 8/20/2015 6:25 PM, Peter W A Wood wrote:


You’re content is no longer valid JSON once you have inserted the
“json=“ (at the PHP developer’s request). There may be a conflict
between the header and the actual content. What happens if you remove
the line setting the httpHeaders?


Thanks Peter. No change, it still fails. I think the PHP guy is 
stripping off the json= anyway and just grabbing the parameters. But 
it does work without the header in LC 6.


I may as well remove the header I suppose.

--
Jacqueline Landman Gay | jac...@hyperactivesw.com
HyperActive Software   | http://www.hyperactivesw.com


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Re: JSON, URL-encode, and UTF-8

2015-08-20 Thread Monte Goulding

 On 21 Aug 2015, at 9:29 am, Monte Goulding mo...@sweattechnologies.com 
 wrote:
 
 That’s a good question. I can’t see anything wrong with the JSON itself after 
 reviewing the file. Validates and formats fine in TextMate. Are you sure they 
 want post and not get or put?

Hmm… I just remembered you said it works in 6 and not 7. Perhaps it’s not 
something simple after all but try not setting the header first...

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Re: JSON, URL-encode, and UTF-8

2015-08-20 Thread Charles Warwick
It will still be useful… what I want to look at is what headers are generated 
and whether or not the JSON is still correctly formatted.

With a copy of the script, I should be able to tell you what is causing it to 
break between the versions.

I have been posting JSON data to PHP in other applications with no problems, so 
it must be something specific to what you are trying to do.

 On 21 Aug 2015, at 11:35 am, J. Landman Gay jac...@hyperactivesw.com wrote:
 
 On 8/20/2015 7:24 PM, Charles Warwick wrote:
 If you are still having issues with this, I am happy to run a packet
 capture against it if you give me a copy of the script…
 
 That way I can tell you what the exact difference is between what LC7
 and LC6 actually post to the server…
 
 Actually, now that I think of it, this probably will show a good deal of 
 difference because the LC 7 version will be UTF8 and the LC 6 version won't.
 
 Which might be the problem, but I don't know. Do you think this would still 
 be useful?
 
 -- 
 Jacqueline Landman Gay | jac...@hyperactivesw.com
 HyperActive Software   | http://www.hyperactivesw.com
 
 
 ___
 use-livecode mailing list
 use-livecode@lists.runrev.com
 Please visit this url to subscribe, unsubscribe and manage your subscription 
 preferences:
 http://lists.runrev.com/mailman/listinfo/use-livecode


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Re: JSON, URL-encode, and UTF-8

2015-08-20 Thread Monte Goulding
What happens if you comment out line 247 of revLibURL stack script? textEncode 
native here seems to be a rather dangerous thing to do…

 On 21 Aug 2015, at 9:45 am, Dave Cragg dcr...@lacscentre.co.uk wrote:
 
 
 On 21 Aug 2015, at 00:33, J. Landman Gay jac...@hyperactivesw.com wrote:
 
 On 8/20/2015 6:25 PM, Peter W A Wood wrote:
 
 You’re content is no longer valid JSON once you have inserted the
 “json=“ (at the PHP developer’s request). There may be a conflict
 between the header and the actual content. What happens if you remove
 the line setting the httpHeaders?
 
 Thanks Peter. No change, it still fails. I think the PHP guy is stripping 
 off the json= anyway and just grabbing the parameters. But it does work 
 without the header in LC 6.
 
 What happens if you remove the httpHeader setting and also UrlEncode tData? 
 
 Dave
 
 
 
 ___
 use-livecode mailing list
 use-livecode@lists.runrev.com
 Please visit this url to subscribe, unsubscribe and manage your subscription 
 preferences:
 http://lists.runrev.com/mailman/listinfo/use-livecode


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Re: JSON, URL-encode, and UTF-8

2015-08-20 Thread Charles Warwick
Encoding the = would break the POST data, as it would no longer be assigned the 
json data itself as a POST variable….

you only want to url encode the contents of the json variable

 On 21 Aug 2015, at 11:17 am, Monte Goulding mo...@sweattechnologies.com 
 wrote:
 
 
 On 21 Aug 2015, at 10:58 am, Peter W A Wood peterwaw...@gmail.com wrote:
 
 put textEncode({   quote  é  quote  : 1}, UTF-8) into tJSON
 put json= before tJSON
 post URLEncode(tJSON) to URL http://Localhost/jacque.php 
 http://localhost/jacque.php
 put textDecode(it, UTF-8”)
 
 You would want to urlEncode tJSON before you put json= before it so the = 
 isn’t encoded.
 
 ___
 use-livecode mailing list
 use-livecode@lists.runrev.com
 Please visit this url to subscribe, unsubscribe and manage your subscription 
 preferences:
 http://lists.runrev.com/mailman/listinfo/use-livecode


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Re: JSON, URL-encode, and UTF-8

2015-08-20 Thread J. Landman Gay

On 8/20/2015 8:46 PM, Charles Warwick wrote:

It will still be useful… what I want to look at is what headers are
generated and whether or not the JSON is still correctly formatted.

With a copy of the script, I should be able to tell you what is
causing it to break between the versions.

I have been posting JSON data to PHP in other applications with no
problems, so it must be something specific to what you are trying to
do.


Okay, thanks very much. I just sent a test script to the list that fails 
reproducibly. You'll need to put in a valid URL though, I can't really 
give out my client's.


--
Jacqueline Landman Gay | jac...@hyperactivesw.com
HyperActive Software   | http://www.hyperactivesw.com


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Re: JSON, URL-encode, and UTF-8

2015-08-20 Thread Peter W A Wood
Jacque

 On 21 Aug 2015, at 10:13, J. Landman Gay jac...@hyperactivesw.com wrote:
 
 Here's a test. This posts just fine in LC 6.x but fails in 7.0.6 and 7.1rc1.
 
 Make a field with this in it:
 
   [{Meals:Yes,Purpose:Business}]
 
 Now put this into a button or card script:
 
 constant kServerURL = https://www.domain.com/results.php 
 https://www.domain.com/results.php  --### use a valid URL here
 
 
 command sendToServer
  if the version  7 then
put fld 1 into tData
put json= before tData
  else
put textEncode(fld 1,UTF8) into tData
put textEncode(json=,UTF8) before tData
  end if
  post tData to kServerURL
  put it into tResponse
  put the result into tErr
  breakpoint -- so you can see it
 end sendToServer
 
 If someone can test this against a simple echo PHP maybe it will tell us 
 something. The real server returns empty in LC 7 and OK in LC 6.

This works fine in LiveCode 7.0.3. I’ll download 7.1RC1 and see if it works 
there too.

Peter

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Re: JSON, URL-encode, and UTF-8

2015-08-20 Thread Charles Warwick
If you are still having issues with this, I am happy to run a packet capture 
against it if you give me a copy of the script… 

That way I can tell you what the exact difference is between what LC7 and LC6 
actually post to the server…

 On 21 Aug 2015, at 9:50 am, Monte Goulding mo...@sweattechnologies.com 
 wrote:
 
 What happens if you comment out line 247 of revLibURL stack script? 
 textEncode native here seems to be a rather dangerous thing to do…
 
 On 21 Aug 2015, at 9:45 am, Dave Cragg dcr...@lacscentre.co.uk wrote:
 
 
 On 21 Aug 2015, at 00:33, J. Landman Gay jac...@hyperactivesw.com wrote:
 
 On 8/20/2015 6:25 PM, Peter W A Wood wrote:
 
 You’re content is no longer valid JSON once you have inserted the
 “json=“ (at the PHP developer’s request). There may be a conflict
 between the header and the actual content. What happens if you remove
 the line setting the httpHeaders?
 
 Thanks Peter. No change, it still fails. I think the PHP guy is stripping 
 off the json= anyway and just grabbing the parameters. But it does work 
 without the header in LC 6.
 
 What happens if you remove the httpHeader setting and also UrlEncode tData? 
 
 Dave
 
 
 
 ___
 use-livecode mailing list
 use-livecode@lists.runrev.com
 Please visit this url to subscribe, unsubscribe and manage your subscription 
 preferences:
 http://lists.runrev.com/mailman/listinfo/use-livecode
 
 
 ___
 use-livecode mailing list
 use-livecode@lists.runrev.com
 Please visit this url to subscribe, unsubscribe and manage your subscription 
 preferences:
 http://lists.runrev.com/mailman/listinfo/use-livecode


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Re: JSON, URL-encode, and UTF-8

2015-08-20 Thread J. Landman Gay

On 8/20/2015 6:45 PM, Dave Cragg wrote:

What happens if you remove the httpHeader setting and also UrlEncode
tData?


Still errors I'm afraid.

Monte wrote:


What happens if you comment out line 247 of revLibURL stack script?
textEncode native here seems to be a rather dangerous thing to do…


Still errors.

Charles wrote:


If you are still having issues with this, I am happy to run a packet
capture against it if you give me a copy of the script…

That way I can tell you what the exact difference is between what
LC7 and LC6 actually post to the server…


That sounds useful. I probably won't understand it but someone else here
might. I'll write you privately if you don't mind. Thanks.

Peter wrote:


I’m not sure if you are URLEncoding the data … that certainly seems
to cause a problem


I'm not URLEncoding the data, though I did try it and it failed. I'm not 
good enough with PHP to even begin to reproduce your setup. I'm a 
one-trick LC pony.


I'm also running a low-grade fever and feel awful, so it's probably 
affecting my thought processes. But I thought I could just post and be 
done with it.


The next hurdle will be getting this to run on iOS which is the target 
platform. I haven't even gone there yet.


--
Jacqueline Landman Gay | jac...@hyperactivesw.com
HyperActive Software   | http://www.hyperactivesw.com


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Re: JSON, URL-encode, and UTF-8

2015-08-20 Thread J. Landman Gay

On 8/20/2015 7:24 PM, Charles Warwick wrote:

If you are still having issues with this, I am happy to run a packet
capture against it if you give me a copy of the script…

That way I can tell you what the exact difference is between what LC7
and LC6 actually post to the server…


Actually, now that I think of it, this probably will show a good deal of 
difference because the LC 7 version will be UTF8 and the LC 6 version won't.


Which might be the problem, but I don't know. Do you think this would 
still be useful?


--
Jacqueline Landman Gay | jac...@hyperactivesw.com
HyperActive Software   | http://www.hyperactivesw.com


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Re: JSON, URL-encode, and UTF-8

2015-08-20 Thread Charles Warwick
If I send that to a PHP script on one of my servers, I receive the JSON data 
correctly from LC7 in the PHP script.

I will just run it against LC6 and make sure it is identical.

If you want, you can post to my PHP script and then we can see how it compares 
between the two versions.  If it works there, it may be an issue with server 
you are posting to or the way that the PHP script is trying to read the data.  
Probably best if you send me a direct e-mail if you want to do that.



 On 21 Aug 2015, at 12:13 pm, J. Landman Gay jac...@hyperactivesw.com wrote:
 
 Here's a test. This posts just fine in LC 6.x but fails in 7.0.6 and 7.1rc1.
 
 Make a field with this in it:
 
   [{Meals:Yes,Purpose:Business}]
 
 Now put this into a button or card script:
 
 constant kServerURL = https://www.domain.com/results.php;  --### use a valid 
 URL here
 
 
 command sendToServer
  if the version  7 then
put fld 1 into tData
put json= before tData
  else
put textEncode(fld 1,UTF8) into tData
put textEncode(json=,UTF8) before tData
  end if
  post tData to kServerURL
  put it into tResponse
  put the result into tErr
  breakpoint -- so you can see it
 end sendToServer
 
 If someone can test this against a simple echo PHP maybe it will tell us 
 something. The real server returns empty in LC 7 and OK in LC 6.
 
 -- 
 Jacqueline Landman Gay | jac...@hyperactivesw.com
 HyperActive Software   | http://www.hyperactivesw.com
 
 ___
 use-livecode mailing list
 use-livecode@lists.runrev.com
 Please visit this url to subscribe, unsubscribe and manage your subscription 
 preferences:
 http://lists.runrev.com/mailman/listinfo/use-livecode
 


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: JSON, URL-encode, and UTF-8

2015-08-20 Thread Peter W A Wood
Jacque

 On 21 Aug 2015, at 05:53, J. Landman Gay jac...@hyperactivesw.com wrote:
 
 Here's what I do:
 
  set the httpHeaders to content-type: application/json
  put convertToJSON() into tData -- produces valid JSON
  put json= before tData
  post tData to kServerURL

You’re content is no longer valid JSON once you have inserted the “json=“ (at 
the PHP developer’s request). There may be a conflict between the header and 
the actual content. What happens if you remove the line setting the httpHeaders?

Regards

Peter

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Re: JSON, URL-encode, and UTF-8

2015-08-20 Thread Dave Cragg

 On 21 Aug 2015, at 00:33, J. Landman Gay jac...@hyperactivesw.com wrote:
 
 On 8/20/2015 6:25 PM, Peter W A Wood wrote:
 
 You’re content is no longer valid JSON once you have inserted the
 “json=“ (at the PHP developer’s request). There may be a conflict
 between the header and the actual content. What happens if you remove
 the line setting the httpHeaders?
 
 Thanks Peter. No change, it still fails. I think the PHP guy is stripping off 
 the json= anyway and just grabbing the parameters. But it does work without 
 the header in LC 6.

What happens if you remove the httpHeader setting and also UrlEncode tData? 

Dave



___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Re: JSON, URL-encode, and UTF-8

2015-08-20 Thread Peter W A Wood
Jacque

 On 21 Aug 2015, at 07:35, J. Landman Gay jac...@hyperactivesw.com wrote:
 
 Right. Works without header in 6, fails in 7. Thanks for looking at my file. 
 I wonder what would happen if I use the LC 6 libURL script in LC 7. Will my 
 unicode go all wonky? The file I sent you is in English but most of the time 
 it won't be.

I ran a very simple test using the message box and a very simple PHP script. I 
was able to post json={JSON} to PHP and get it back.

In the message box (using LC 7..0.3)

post textEncode(json={  quote  é  quote  : 1}, UTF-8) to  URL 
http://Localhost/jacque.php;
put textDecode(it, UTF-8”)

The PHP script:

?php 
  echo($_POST[json]);
?

The result in the message box:

{é: 1}

This would indicate your issue is not caused by a bug.

I’m not sure if you are URLEncoding the data … that certainly seems to cause a 
problem

Revised LiveCode
put textEncode({   quote  é  quote  : 1}, UTF-8) into tJSON
put json= before tJSON
post URLEncode(tJSON) to URL http://Localhost/jacque.php;
put textDecode(it, UTF-8”)

Result 
PHP sends back an empty response.

Hope this is of some help.

Peter
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Re: JSON, URL-encode, and UTF-8

2015-08-20 Thread J. Landman Gay

On 8/20/2015 6:32 PM, Monte Goulding wrote:



On 21 Aug 2015, at 9:29 am, Monte Goulding
mo...@sweattechnologies.com wrote:

That’s a good question. I can’t see anything wrong with the JSON
itself after reviewing the file. Validates and formats fine in
TextMate. Are you sure they want post and not get or put?


Hmm… I just remembered you said it works in 6 and not 7. Perhaps it’s
not something simple after all but try not setting the header
first...


Right. Works without header in 6, fails in 7. Thanks for looking at my 
file. I wonder what would happen if I use the LC 6 libURL script in LC 
7. Will my unicode go all wonky? The file I sent you is in English but 
most of the time it won't be.


--
Jacqueline Landman Gay | jac...@hyperactivesw.com
HyperActive Software   | http://www.hyperactivesw.com


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Re: JSON, URL-encode, and UTF-8

2015-08-20 Thread J. Landman Gay

Here's a test. This posts just fine in LC 6.x but fails in 7.0.6 and 7.1rc1.

Make a field with this in it:

   [{Meals:Yes,Purpose:Business}]

Now put this into a button or card script:

constant kServerURL = https://www.domain.com/results.php;  --### use a 
valid URL here



command sendToServer
  if the version  7 then
put fld 1 into tData
put json= before tData
  else
put textEncode(fld 1,UTF8) into tData
put textEncode(json=,UTF8) before tData
  end if
  post tData to kServerURL
  put it into tResponse
  put the result into tErr
  breakpoint -- so you can see it
end sendToServer

If someone can test this against a simple echo PHP maybe it will tell us 
something. The real server returns empty in LC 7 and OK in LC 6.


--
Jacqueline Landman Gay | jac...@hyperactivesw.com
HyperActive Software   | http://www.hyperactivesw.com

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: JSON, URL-encode, and UTF-8

2015-08-20 Thread J. Landman Gay
I'm still struggling with this. I have a valid JSON string, verified by 
a web-checking site and by the PHP developer. He wants me to POST it 
this way:


json=JSON string

It doesn't work. He says the server receives it but it is not passed to 
the PHP script because the main parameter is empty. Here's what I do:


  set the httpHeaders to content-type: application/json
  put convertToJSON() into tData -- produces valid JSON
  put json= before tData
  post tData to kServerURL

The result is empty. The developer has set up the PHP to return the 
values back to me for testing, but it is also always empty. He says 
this means there is no main parameter, but he also said adding json= 
to the front would provide that, he will just grab the params from what 
follows.


The URL is https if that matters. I have also tried URLEncoding the JSON 
but it didn't help. I also tried removing the custom header.


He pointed me to this web site: https://www.hurl.it/ When I set it to 
send JSON and enter the same params there, it POSTs successfully to the 
server.


How would you POST a JSON string to a PHP script on a secure server?

--
Jacqueline Landman Gay | jac...@hyperactivesw.com
HyperActive Software   | http://www.hyperactivesw.com

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: JSON, URL-encode, and UTF-8

2015-08-20 Thread Monte Goulding
Is your convertToJSON function returning UTF8? I’m not sure what LC 7 does when 
it concatenates “json=“ to a UTF8 string. If for example that json= is UTF16 
and the rest of the data is UTF8 it’s not surprising the server is freaking 
out. Try:

put textEncode(“json=“,”UTF8”) before tData

 On 21 Aug 2015, at 7:53 am, J. Landman Gay jac...@hyperactivesw.com wrote:
 
 I'm still struggling with this. I have a valid JSON string, verified by a 
 web-checking site and by the PHP developer. He wants me to POST it this way:
 
 json=JSON string
 
 It doesn't work. He says the server receives it but it is not passed to the 
 PHP script because the main parameter is empty. Here's what I do:
 
  set the httpHeaders to content-type: application/json
  put convertToJSON() into tData -- produces valid JSON
  put json= before tData
  post tData to kServerURL
 
 The result is empty. The developer has set up the PHP to return the values 
 back to me for testing, but it is also always empty. He says this means 
 there is no main parameter, but he also said adding json= to the front 
 would provide that, he will just grab the params from what follows.
 
 The URL is https if that matters. I have also tried URLEncoding the JSON but 
 it didn't help. I also tried removing the custom header.
 
 He pointed me to this web site: https://www.hurl.it/ When I set it to send 
 JSON and enter the same params there, it POSTs successfully to the server.
 
 How would you POST a JSON string to a PHP script on a secure server?
 
 -- 
 Jacqueline Landman Gay | jac...@hyperactivesw.com
 HyperActive Software   | http://www.hyperactivesw.com
 
 ___
 use-livecode mailing list
 use-livecode@lists.runrev.com
 Please visit this url to subscribe, unsubscribe and manage your subscription 
 preferences:
 http://lists.runrev.com/mailman/listinfo/use-livecode


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Re: JSON, URL-encode, and UTF-8

2015-08-20 Thread J. Landman Gay

Okay, addendum: It works fine in LC 6.7.6. It fails entirely in 7.0.6.

I wish I'd tried that sooner. We need 7.x because of the unicode support.


On 8/20/2015 4:53 PM, J. Landman Gay wrote:

I'm still struggling with this. I have a valid JSON string, verified by
a web-checking site and by the PHP developer. He wants me to POST it
this way:

json=JSON string

It doesn't work. He says the server receives it but it is not passed to
the PHP script because the main parameter is empty. Here's what I do:

   set the httpHeaders to content-type: application/json
   put convertToJSON() into tData -- produces valid JSON
   put json= before tData
   post tData to kServerURL

The result is empty. The developer has set up the PHP to return the
values back to me for testing, but it is also always empty. He says
this means there is no main parameter, but he also said adding json=
to the front would provide that, he will just grab the params from what
follows.

The URL is https if that matters. I have also tried URLEncoding the JSON
but it didn't help. I also tried removing the custom header.

He pointed me to this web site: https://www.hurl.it/ When I set it to
send JSON and enter the same params there, it POSTs successfully to the
server.

How would you POST a JSON string to a PHP script on a secure server?




--
Jacqueline Landman Gay | jac...@hyperactivesw.com
HyperActive Software   | http://www.hyperactivesw.com

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: JSON, URL-encode, and UTF-8

2015-08-20 Thread J. Landman Gay

Thanks, but still no go. I get the same errors.

Is anyone posting from LC 7? I also just tried 7.1rc1 but it doesn't 
work either.


On 8/20/2015 5:04 PM, Monte Goulding wrote:

Is your convertToJSON function returning UTF8? I’m not sure what LC 7 does when 
it concatenates “json=“ to a UTF8 string. If for example that json= is UTF16 
and the rest of the data is UTF8 it’s not surprising the server is freaking 
out. Try:

put textEncode(“json=“,”UTF8”) before tData


On 21 Aug 2015, at 7:53 am, J. Landman Gay jac...@hyperactivesw.com wrote:

I'm still struggling with this. I have a valid JSON string, verified by a 
web-checking site and by the PHP developer. He wants me to POST it this way:

json=JSON string

It doesn't work. He says the server receives it but it is not passed to the PHP 
script because the main parameter is empty. Here's what I do:

  set the httpHeaders to content-type: application/json
  put convertToJSON() into tData -- produces valid JSON
  put json= before tData
  post tData to kServerURL

The result is empty. The developer has set up the PHP to return the values back to me for testing, but 
it is also always empty. He says this means there is no main parameter, but he also 
said adding json= to the front would provide that, he will just grab the params from what follows.

The URL is https if that matters. I have also tried URLEncoding the JSON but it 
didn't help. I also tried removing the custom header.

He pointed me to this web site: https://www.hurl.it/ When I set it to send 
JSON and enter the same params there, it POSTs successfully to the server.

How would you POST a JSON string to a PHP script on a secure server?

--
Jacqueline Landman Gay | jac...@hyperactivesw.com
HyperActive Software   | http://www.hyperactivesw.com

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode



___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode




--
Jacqueline Landman Gay | jac...@hyperactivesw.com
HyperActive Software   | http://www.hyperactivesw.com


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Re: JSON, URL-encode, and UTF-8

2015-08-17 Thread Monte Goulding

 On 18 Aug 2015, at 6:54 am, J. Landman Gay jac...@hyperactivesw.com wrote:
 
 Thanks Monte. The JSON is created by EasyJSON from a LC array. Most of the 
 values in the array are in foreign languages with lots of non-ascii 
 characters, and those will become the values in the parameter string that I 
 will send in a POST. It doesn't look like EasyJSON does any UTF8 encoding 
 when creating the JSON.

I haven’t used EasyJSON because it was done after mergJSON so I can’t confirm 
about the utf8. If you are posting JSON then you don’t need to urlEncode. Just 
set the content type header to application/json
 
 So I guess I need to UTF8 encode the array before sending it to the JSON 
 parser, then URL-encode the JSON. Is it possible to textEncode a whole array 
 at once without looping through all the elements?

No, just UTF8 encode any elements (or keys) that’s not likely to be ASCII.
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Re: JSON, URL-encode, and UTF-8

2015-08-17 Thread Monte Goulding
I think we would need to see the API to know about the urlEncoding. Is it a 
parameter in your query string? If you need to urlEncode it will be the last 
thing you do. If you are using one of the script libraries the UTF8 encoding 
may be done for you. If you are using mergJSON then UTF8 encode anything that's 
not ASCII before you JSON encode.

Cheers

Monte

Sent from my iPhone

 On 18 Aug 2015, at 4:41 am, J. Landman Gay jac...@hyperactivesw.com wrote:
 
 I've confused myself. I need to send JSON to a server. The values will have 
 foreign characters in them. So I think I need to use textEncode to convert it 
 to UTF8 and also it needs to be URL encoded. Is that right? And if so, what 
 order do I do it in?
 
 Do I URL-encode each value in the array, then create the JSON, then 
 textEncode that? Or some other order? Or does textEncoding remove the need to 
 URL encode?

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: JSON, URL-encode, and UTF-8

2015-08-17 Thread J. Landman Gay
Thanks Monte. The JSON is created by EasyJSON from a LC array. Most of 
the values in the array are in foreign languages with lots of non-ascii 
characters, and those will become the values in the parameter string 
that I will send in a POST. It doesn't look like EasyJSON does any UTF8 
encoding when creating the JSON.


So I guess I need to UTF8 encode the array before sending it to the JSON 
parser, then URL-encode the JSON. Is it possible to textEncode a whole 
array at once without looping through all the elements?



On 8/17/2015 3:28 PM, Monte Goulding wrote:

I think we would need to see the API to know about the urlEncoding.
Is it a parameter in your query string? If you need to urlEncode it
will be the last thing you do. If you are using one of the script
libraries the UTF8 encoding may be done for you. If you are using
mergJSON then UTF8 encode anything that's not ASCII before you JSON
encode.

Cheers

Monte

Sent from my iPhone


On 18 Aug 2015, at 4:41 am, J. Landman Gay
jac...@hyperactivesw.com wrote:

I've confused myself. I need to send JSON to a server. The values
will have foreign characters in them. So I think I need to use
textEncode to convert it to UTF8 and also it needs to be URL
encoded. Is that right? And if so, what order do I do it in?

Do I URL-encode each value in the array, then create the JSON, then
textEncode that? Or some other order? Or does textEncoding remove
the need to URL encode?


___ use-livecode mailing
list use-livecode@lists.runrev.com Please visit this url to
subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode




--
Jacqueline Landman Gay | jac...@hyperactivesw.com
HyperActive Software   | http://www.hyperactivesw.com

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode