SOLVED - Post to web service on iOS

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

juanjo
Posts: 35
Joined: Wed Jul 31, 2013 10:31 am

SOLVED - Post to web service on iOS

Post by juanjo » Fri Aug 30, 2013 7:30 pm

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
 
Last edited by juanjo on Wed Sep 11, 2013 5:36 pm, edited 1 time in total.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Post to web service on iOS

Post by Simon » Fri Aug 30, 2013 7:50 pm

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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

juanjo
Posts: 35
Joined: Wed Jul 31, 2013 10:31 am

Re: Post to web service on iOS

Post by juanjo » Sat Aug 31, 2013 12:59 am

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.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Post to web service on iOS

Post by Simon » Sat Aug 31, 2013 1:21 am

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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

juanjo
Posts: 35
Joined: Wed Jul 31, 2013 10:31 am

Re: Post to web service on iOS

Post by juanjo » Sat Aug 31, 2013 1:44 am

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.)

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Post to web service on iOS

Post by Simon » Sat Aug 31, 2013 1:53 am

Well you could just copy the IDE headers and use "set httpHeaders".
Should make your device appear as a desktop machine.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

juanjo
Posts: 35
Joined: Wed Jul 31, 2013 10:31 am

Re: Post to web service on iOS

Post by juanjo » Sat Aug 31, 2013 2:03 am

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)

juanjo
Posts: 35
Joined: Wed Jul 31, 2013 10:31 am

Re: Post to web service on iOS

Post by juanjo » Sat Aug 31, 2013 12:48 pm

Any other idea?

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Post to web service on iOS

Post by Simon » Sat Aug 31, 2013 9:29 pm

Hi juanjo,
No not really.
As I can't test your stack I don't know where to look. :(

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

juanjo
Posts: 35
Joined: Wed Jul 31, 2013 10:31 am

Re: Post to web service on iOS

Post by juanjo » Sat Aug 31, 2013 11:14 pm

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!

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Post to web service on iOS

Post by Simon » Sun Sep 01, 2013 3:01 am

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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

juanjo
Posts: 35
Joined: Wed Jul 31, 2013 10:31 am

Re: Post to web service on iOS

Post by juanjo » Sun Sep 01, 2013 10:34 am

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…

viro
Posts: 52
Joined: Fri Jul 05, 2013 6:59 pm
Location: Germany, Hesse

Re: Post to web service on iOS

Post by viro » Sun Sep 01, 2013 11:06 am

Did you try to set your UserAgent to "User-Agent: YourAppName"?

i made stack for you to check headers
Attachments
check_last_sent_received_headers.zip
(3.98 KiB) Downloaded 247 times
the funniest thing about this particular signature is that by the time you realize it doesn't say anything it's too late to stop reading it

juanjo
Posts: 35
Joined: Wed Jul 31, 2013 10:31 am

Re: Post to web service on iOS

Post by juanjo » Sun Sep 01, 2013 12:00 pm

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.

juanjo
Posts: 35
Joined: Wed Jul 31, 2013 10:31 am

Re: Post to web service on iOS

Post by juanjo » Sun Sep 01, 2013 12:36 pm

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.
 

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”