Page 1 of 2

SOLVED - Post to web service on iOS

Posted: Fri Aug 30, 2013 7:30 pm
by juanjo
Hello.

I'm trying to access a web service from iOS using post.

In the editor works fine but not on iOS, not in the simulator nor in the device.

It returns nothing, neither in it nor in the result.
I think it don't even try to send the request.
 

Code: Select all


-- Only needs a button with this code and a text field called 'consola'

local arrayListado
on mouseUp
   put "borrado" into cd fld "consola"
   Listado
end mouseUp

private command Listado
   put "" into datosPeticion
   put "<?xml version='1.0' encoding='utf-8'?>" \
         & return & "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>" \
         & return & tab & "<soap:Body>" \
         & return & tab & tab & "<Listado xmlns=" & quote & "http://ws.escrol.es/" & quote & " />" \
         & return & tab & "</soap:Body>" \
         & return & "</soap:Envelope>" \
         into datosPeticion   
   set the httpHeaders to "POST /WebService.asmx HTTP/1.1" \
         & return & "Host: ws.escrol.es" \
         & return & "Content-Type: text/xml; charset=utf-8" \
         & return & "Content-Length: " & the length of datosPeticion \
         & return & "SOAPAction: http://ws.escrol.es/Listado"
   
   
   put "petición iniciada" &cr&cr into field "consola"
   
   
   post datosPeticion to url "http://ws.escrol.es/WebService.asmx"
   put the result into resultado
   put it into datosRespuesta
   
   
   put "the result: " & resultado &cr&cr after field "consola"
   put "it: " & datosRespuesta &cr&cr after field "consola"
   put "petición terminada"&cr&cr after field "consola"
   
   ---
end Listado
 

Re: Post to web service on iOS

Posted: Fri Aug 30, 2013 7:50 pm
by Simon
Hi juanjo,
I'm getting "the result: error 500 Internal Server Error" using your code in the IDE.

And you should not post the same question twice in the forums.

Simon

Re: Post to web service on iOS

Posted: Sat Aug 31, 2013 12:59 am
by juanjo
Thanks Simon.

As I said, the problem is not having an error 500 in the IDE, but an empty response in iOS (simulator and device).

I'll appreciate any help.

Re: Post to web service on iOS

Posted: Sat Aug 31, 2013 1:21 am
by Simon
Hi juanjo,
This may be an httpHeaders issue.
If it works in the IDE (for you) but not on the device, one of the differences is mobile sends out a "mobile" header during a post.
After the post use "answer libURLLastRHHeaders" to see the differences.

Simon

Re: Post to web service on iOS

Posted: Sat Aug 31, 2013 1:44 am
by juanjo
Hi again!

I tried to use answer libURLLastRHHeaders() but it stops the app.
It works in the IDE, but not in the iOS simulator.

In the dictionary page for 'post' they say The Android and iOS engines do not support 'libUrl', so maybe I'll need another way to analyze the headers, or documentation source to compose the right ones.

___
(I tried libURLLastHTTPHeaders too.)

Re: Post to web service on iOS

Posted: Sat Aug 31, 2013 1:53 am
by Simon
Well you could just copy the IDE headers and use "set httpHeaders".
Should make your device appear as a desktop machine.

Simon

Re: Post to web service on iOS

Posted: Sat Aug 31, 2013 2:03 am
by juanjo
The only difference was the user agent. I added the line "User-Agent: LiveCode (MacOS)", but I get the same result (empty it and the result)

Re: Post to web service on iOS

Posted: Sat Aug 31, 2013 12:48 pm
by juanjo
Any other idea?

Re: Post to web service on iOS

Posted: Sat Aug 31, 2013 9:29 pm
by Simon
Hi juanjo,
No not really.
As I can't test your stack I don't know where to look. :(

Simon

Re: Post to web service on iOS

Posted: Sat Aug 31, 2013 11:14 pm
by juanjo
Hi again Simon,

If you refer to the error 500, the server is working now.
(Anyway, even with the error, I should obtain the error in the result…)

And by the way, thanks for your help!

Re: Post to web service on iOS

Posted: Sun Sep 01, 2013 3:01 am
by Simon
Hi juanjo,
This was pain.
Seems the simulator doesn't see that it's online when running an LC app.
add a button with this:

Code: Select all

on mouseUp
put url "http://www.google.com" into temp
answer temp
end mouseUp
Make sure that your app is connected to the web.
From the sim either a restart or going to Safari first and actually watching a page load (not cache). Both seemed to work here I'll let you figure it out.

With just your code I was able to get the same response from IDE and sim.

The tip off was "it" was coming back way too fast in the sim.

If anyone knows actually why this happens then please pitch-in.

Simon

Re: Post to web service on iOS

Posted: Sun Sep 01, 2013 10:34 am
by juanjo
Thank you Simon.

Perhaps we are approaching.
Although previously I've made sure that both are connected to internet, I can not do any reading, not in the simulator nor in the iPad (it's still working in the IDE).

I think LiveCode is somehow caching the connection, or the request is missformated only for iOS, and does not reach out.
I added a "Cache-Control: no-cache" line to the header, and I have verified "cachedURLs" (which is empty) and I really do not know what else to try.

That's very frustrating…

Re: Post to web service on iOS

Posted: Sun Sep 01, 2013 11:06 am
by viro
Did you try to set your UserAgent to "User-Agent: YourAppName"?

i made stack for you to check headers

Re: Post to web service on iOS

Posted: Sun Sep 01, 2013 12:00 pm
by juanjo
Hi viro, thank you.

Yes, I tried with the User-Agent and Cache-Control headers and I also think the problem may be there.
Either that, or the Post command on LiveCode for iOS is broken…

The problem is that libURLLastHTTPHeaders belongs to libURL, and this library don't works on iOS, so no way to see the headers actually sent from the simulator or device.

In fact, I think, as Simon said too, that is not having any communication.

Re: Post to web service on iOS

Posted: Sun Sep 01, 2013 12:36 pm
by juanjo
In the dictionary entry for Post, says

"The Android and iOS engines do not support 'libUrl' but allow you to use post in the background."

If it can run in the background, there should be an asynchronous way to pick up the Post status and response.
I've verified that width can not be used to declare a callback message, and now I'm testing with urlProgress that although is specific for mobile, does not seem to do anything.