Link to home
Create AccountLog in
Avatar of birstein
birstein

asked on

Problem Posting XML Data Stream with ASP

Hi All:

I need to post changes to user email addresses via XML to my email vendor's database. Unfortunately, their support guy only knows Perl and I only know ASP! Also, the email vendor's help docs are really terse. Here's what it says:

"Sending data to our XML API requires that you use a scripting language to post to scripts on our server. Languages like Perl, PHP, ASP, .NET, Java, and C++ all provide for user agents that will send form data in HTTP POST format to our server. We strongly recommend that you use HTTP POST (and not GET) so you aren't limited by the size of the XML commands.

You can POST data to your account automatically using our XML API from an external script with this:

http://www.icebase.com/dbadmin/xml_post.ice

You will only need to send data by HTTP POST or HTTPS POST with these names:

username
password
xml_body

The XML datastream has 5 top-level data types:
•      <Record> for uploading contact information,
•      <Edition> for uploading edition content,
•      <ListSettings> for updating list settings
•      <LinkLibrary> for uploading links into your Link Library, and
•      <Send> to use XML to send emails and broadcast to your lists"

Further down it says you can change an email on their database with this data stream:

"Changing a Contact's Email Address
Because CoolerEmail uses the email address as the primary key for each contact, you must use a separate command inside the <Record> tags to change a contact. The XML command is ChangeEmail, and it would look something like this:
<Record>
<Email>someone@something.com</Email>
<ChangeEmail>someone@another.com</ChangeEmail>
</Record>"

So I write the following ASP:

<%
xmldata = "<?xml version=""1.0""?>"
xmldata=xmldata & "<Record>"
xmldata=xmldata & "<Email>contact@birstein.com</Email>"
xmldata=xmldata & "<ChangeEmail>contact2@birstein.com</ChangeEmail>"
xmldata=xmldata & "</Record>"


set objSrvHTTP = Server.CreateObject ("MSXML2.ServerXMLHTTP")
objSrvHTTP.open "POST","https://www.icebase.com/dbadmin/xml_post.ice?username=birstein&password=midnight",false
objSrvHTTP.send(xmldata)

Response.Write objSrvHTTP.responseText
%>

and am rewarded with the following text in the browser when I run the ASP:

"Yes No valid username provided. Operation aborted."

The tech guy is sure that the username and password are separate formdata name/value pairs, not included in the XML stream.

Does anybody have any ideas???

THANKS!

Kathryn

 
Avatar of BigRat
BigRat
Flag of France image

When you set up a POST request using the XML object(s) (Server or client) you have to construct the post data in a string. The format is exactly as if it were a GET request :-

   var poststring;

   poststring='username=' + escape(username) + '&password=' + escape(password);

would be a bit of Javascript to do this. So now you must add on the XML body :-

   poststring='username=' + escape(username) + '&password=' + escape(password) +
                    '&xmlbody=' + escape(xmldata);

where the xmldata is as you have above.

Then you "post" the string :-
   
     objServer.post(poststring);

OK?
   
Avatar of birstein
birstein

ASKER

Dear Big Rat:

It seems like I'm getting somewhere because now I'm getting a different error message with the following code. I think its probably some crazy double quote problem. Any ideas?

<%
xmldata = "<?xml version=""1.0""?>"
xmldata=xmldata & "<Record>"
xmldata=xmldata & "<Email>contact@birstein.com</Email>"
xmldata=xmldata & "<ChangeEmail>contact2@birstein.com</ChangeEmail>"
xmldata=xmldata & "</Record>"


Dim poststring

poststring="username=birstein&password=midnight&xmlbody=" & xmldata

set objSrvHTTP = Server.CreateObject ("MSXML2.ServerXMLHTTP")
objSrvHTTP.open "POST","https://www.icebase.com/dbadmin/xml_post.ice?",false
objSrvHTTP.send(poststring)

Response.Write objSrvHTTP.responseText
%>
ASKER CERTIFIED SOLUTION
Avatar of BigRat
BigRat
Flag of France image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Sorry it took so long to Accept and give points. Been overwhelmed!