It turns out to be a lot more work, but after a day of googling and trying i got it to work with the UrlFetchApp
function UrlFetchAppDetermineCountryFromIP_(ipAddress) {
var xml =
"<?xml version="1.0" encoding="UTF-8"?>"
+"<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">"
+"<SOAP-ENV:Body>"
+"<GetGeoIP xmlns="http://www.webservicex.net/">"
+"<IPAddress>"+ ipAddress +"</IPAddress>"
+"</GetGeoIP>"
+"</SOAP-ENV:Body>"
+"</SOAP-ENV:Envelope>"
var options =
{
"method" : "post",
"contentType" : "text/xml",
"payload" : xml
};
var result = UrlFetchApp.fetch("http://www.webservicex.net/geoipservice.asmx?wsdl", options);
var xmlResult = XmlService.parse(result).getRootElement();
var soapNamespace = xmlResult.getNamespace("soap");
var getGeoIPResponse = xmlResult.getChild("Body", soapNamespace).getChildren()[0];
var getGeoIPResponseNamespace = getGeoIPResponse.getNamespace();
return getGeoIPResponse
.getChild("GetGeoIPResult", getGeoIPResponseNamespace)
.getChild("CountryCode", getGeoIPResponseNamespace)
.getText();
}
It should probely be posable to build the payload xml with the XmlService, however i tryed that for a few hours and was unable to put the 4 xmlns attributes on the Evnelope element, wich caused the webservice request to fail
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…