[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: LuaSoap and argument containting an '&'
- From: Sean Conner <sean@...>
- Date: Wed, 18 Jan 2012 18:01:35 -0500
It was thus said that the Great Laurent FAILLIE once stated:
> Hello,
>
> How to encode an argument that contains an ampersand ?
>
> My code is the following :
>
> client.call {
> url = rendez_vous,
> soapaction = "nanaafoutre",
> method = "Report",
> entries = {
> {
> tag="status",
> attr = { "xsi:type", ["xsi:type"] = "xsd:boolean", },
> rc == 0 and "true" or "false"
> },{
> tag="output",
> attr = { "xsi:type", ["xsi:type"] = "xsd:string", },
> res
> }
> }
> }
>
> but evrytime the string res contains "&" character, I got following error :
>
> lua: /usr/local/share/lua/5.1/soap/client.lua:78: Error on request: 1
>
> <?xml version="1.0" encoding="UTF-8"?>
> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><SOAP-ENV:Fault><faultcode>SOAP-ENV:Client</faultcode><faultstring>Bad Request</faultstring></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>
>
> So what have I to do ?
This is less a Lua issue and more of an XML issue, but the answer is: any
time you want to encode "&" in an XML document (and SOAP is encoded in XML)
you need to convert it to "&".
An easy way to do that is
res = res:gsub("%&","&")
A better way is to see of the library you are using can encode strings for
XML and use that.
-spc (As there are some other characters you may need to watch out for)