Click here to Skip to main content
15,891,597 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I got a XML source, is a php url like "http://www.abc.com/status.php

I need to submit xml to this url by post method,
for example:
XML
<?xml version="1.0" encoding="UTF-8" ?>
<request>
<hmcreflist>
<hmcref>W1009430</hmcref>
</hmcreflist>
</request>



then , it will return XML back
for example:
XML
<?xml version="1.0" encoding="UTF-8" ?>
<QBOOKINGSTATUS>
<XML_RESULT>
<HMCREFLIST>
<HMCREF>W1009430</HMCREF>
<REFNO>A12346</REFNO>
<STATUSCODE>OR</STATUSCODE>
<STATUSDESC>On Request</STATUSDESC>
<CANCELDESC />
</HMCREFLIST>
</XML_RESULT>
</QBOOKINGSTATUS>



How can I design a ssis package to do this action?
Posted
Updated 12-Aug-12 4:45am
v3

1 solution

Use Script Task and do post as :
C#
public static string POST(string postData, string url, string referer, string cookie)
{
    string retValue = string.Empty;
    try
    {
        byte[] byteArray = Encoding.UTF8.GetBytes(postData);
        HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
        request.Method = "POST";
        request.KeepAlive = true;
        request.AllowAutoRedirect = false;
        request.Accept = "*/*";
        request.ContentType = "text/xml";
        if (!string.IsNullOrEmpty(cookie))
            request.Headers.Add(HttpRequestHeader.Cookie, cookie);

        if (!string.IsNullOrEmpty(referer))
            request.Referer = referer;
        request.ContentLength = byteArray.Length;
        request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5";
        //   request.Proxy = null;
        Stream dataStream = request.GetRequestStream();
        dataStream.Write(byteArray, 0, byteArray.Length);
        dataStream.Close();
        try
        {
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Stream dataResponseStream = response.GetResponseStream();
            StreamReader SR = new StreamReader(dataResponseStream, Encoding.UTF8);
            retValue = SR.ReadToEnd();
            response.Close();
            dataStream.Close();
            SR.Close();
            request.Abort();
        }
        catch
        {
        }
    }
    catch
    {
    }
    return retValue;
}


how to call the above method :
string postdata = oReqDoc.InnerXml; //oReqDoc is the XMLDoc you need to post. If you have xml as in text form simply sent it.
string url ="http://www.abc.com/status.php php";
pass referrer and cookie as ""
now call POST as :
C#
string strReponse = POST(postdata, url, "", "");

now you can inspect if you have got the right output xml.

you can try the following snippet too to convert string to xml:

C#
XmlDocument doc = new XmlDocument{ XmlResolver = null };
            doc.LoadXml(strReponse);
            XmlNode newNode = doc.DocumentElement; 


Note: You may need following namespaces:
C#
using System.Net;
using System.IO;
using System.Web;
using System.Xml;



Thanks,

Kuthuparakkal
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900