如何使用SSIS将XML提交到php文件? [英] How can I use SSIS submit XML to a php file ?
问题描述
我有一个XML源,它是一个php网址,例如" http://www.abc.com/status.php
我需要通过post方法
将xml提交到该URL
例如:
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 version="1.0" encoding="UTF-8" ?>
<request>
<hmcreflist>
<hmcref>W1009430</hmcref>
</hmcreflist>
</request>
然后,它将返回XML
例如:
then , it will return XML back
for example:
<?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?
推荐答案
使用脚本任务并将其发布为:
Use Script Task and do post as :
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;
}
如何调用上述方法:
字符串postdata = oReqDoc.InnerXml; //oReqDoc是您需要发布的XMLDoc.如果您有xml格式的文本,只需发送即可.
字符串url ="http://www.abc.com/status.php php";
将引荐来源网址和Cookie传递为"
现在将POST称为:
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 :
string strReponse = POST(postdata, url, "", "");
现在您可以检查是否具有正确的输出xml.
您也可以尝试使用以下代码片段将字符串转换为xml:
now you can inspect if you have got the right output xml.
you can try the following snippet too to convert string to xml:
XmlDocument doc = new XmlDocument{ XmlResolver = null };
doc.LoadXml(strReponse);
XmlNode newNode = doc.DocumentElement;
注意:您可能需要以下名称空间:
Note: You may need following namespaces:
using System.Net;
using System.IO;
using System.Web;
using System.Xml;
谢谢,
Kuthuparakkal
Thanks,
Kuthuparakkal
这篇关于如何使用SSIS将XML提交到php文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!