Classic ASP and Subscriber.Add

Hi, I have found a piece og code an I am trying to add subscribers through the API.

But I get this error:

soap:ClientSystem.Web.Services.Protocols.SoapException: Server was unable to read request. ---> System.InvalidOperationException: There is an error in XML document (1, 397). ---> System.FormatException: Input string was not in a correct format. at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) at System.Xml.XmlConvert.ToInt32(String s) at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read22_SubscriberAdd() at Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer16.Deserialize(XmlSerializationReader reader) at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events) --- End of inner exception stack trace --- at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events) at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle) at System.Web.Services.Protocols.SoapServerProtocol.ReadParameters() --- End of inner exception stack trace --- at System.Web.Services.Protocols.SoapServerProtocol.ReadParameters() at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()


And the code I use is this:

dim apikey, listid, name, email, newsletter, postdata, response

apikey = "myAPI"
listid = "myListId"

name = Request.Form("navn")
email = Request.Form("email")

If email <> ""  Then

    postdata = "<?xml version=""1.0"" encoding=""utf-8""?>"
    postdata = postdata & "<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/"">"
    postdata = postdata & "<soap:Body>"
    postdata = postdata & "    <Subscriber.Add xmlns=""http://app.campaignmonitor.com/api/"">"
    postdata = postdata & "        <ApiKey>" & apikey & "</ApiKey>"
    postdata = postdata & "        <ListID>" & listid & "</ListID>"
    postdata = postdata & "        <Email>" & email & "</Email>"
    postdata = postdata & "        <Name>" & name & "</Name>"
    postdata = postdata & "    </Subscriber.Add>"
    postdata = postdata & "</soap:Body>"
    postdata = postdata & "</soap:Envelope>"
   
    response.write postdata
    Dim xmlhttp
    'Set xmlhttp=Server.CreateObject("Microsoft.XMLHTTP")
    'Set xmlhttp=Server.CreateObject("MSXML2.ServerXMLHTTP.4.0")
    Set xmlhttp=Server.CreateObject("MSXML2.ServerXMLHTTP")
   
    xmlhttp.open "POST","http://app.campaignmonitor.com/api/api.asmx" ,false

    xmlhttp.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
    xmlhttp.setRequestHeader "SOAPAction", """http://app.campaignmonitor.com/api/Subscriber.Add"""

    xmlhttp.send postdata
   
    response = xmlhttp.responseText
   
    Response.Write response


End If

See why 200,000 companies worldwide love Campaign Monitor.

From Australia to Zimbabwe, and everywhere in between, companies count on Campaign Monitor for email campaigns that boost the bottom line.

Get started for free