未收到 PHP 中通过 POST 发送的 XML

发布于 2024-12-10 04:46:50 字数 3755 浏览 0 评论 0原文

我正在使用 BlueHornet API 发送电子邮件,特别是 legacy.send_campaign 方法。我正在更新客户现有的 API 调用,并已收到指示

“使用下面指定的参数 POST XML 消息。请务必包含元素并将其值设置为“Y”。POST 响应消息将包含元素和; 元素。

这是提供的格式:

<api>
    <authentication>
        <api_key>ClientAPIKey</api_key>
        <shared_secret>ClientSharedSecret</shared_secret>
        <response_type>xml</response_type>
    </authentication>
    <data>
        <methodCall>
            <methodName>legacy.send_campaign</methodName>
            <grp>ClientEmailGroupCode</grp>
            <rich_mbody><![CDATA[<html...LONG HTML BLOCK...</html>]]></rich_mbody>
            <text_mbody><![CDATA[...LONG TEXT BODY...]]></text_mbody>
            <reply_email>ClientReplyEmail</reply_email>
            <from_email>ClientFromEmail</from_email>
            <fromdesc>ClientFromName</fromdesc>
            <msubject>ClientEmailSubject</msubject>
            <send>Y</send>
            <track_links>1</track_links>
        </methodCall>
    </data>
</api>

API 受密码保护,但我可以根据请求发布文档。

我已确认 ClientAPIKeyClientSharedSecretClientEmailGroupCode 有效,但我的测试不成功发送以下内容(使用 fsockopen() FWIW):

POST /api/xmlrpc/index.php HTTP/1.0
Host: echoN.bluehornet.com
Content-Type: text/xml;charset=utf-8
Content-Length: 21551

<?xml version="1.0"?>
<api>
    <authentication>...as above...</authentication>
    <data>...as above...</data>
</api>

导致第三个-。一方服务器发送回此 XML 响应,指示错误:

HTTP/1.1 200 OK
Date: Thu, 13 Oct 2011 13:18:50 GMT
Server: Apache/1.3.41 (Unix)
Cache-Control: max-age=18000
Expires: Thu, 13 Oct 2011 18:18:50 GMT
Connection: close
Content-Type: text/xml;charset=utf-8
Set-Cookie: BIGipServerBH-gen-80=387268618.20480.0000; path=/

<!--?xml version="1.0" encoding="utf-8"?-->
<methodresponse><item><error><!--[CDATA[1]]--></error>
<responsetext><!--[CDATA[No XML Data Passed.]]--></responsetext>
<responsedata><responsenum><!--[CDATA[1]]--></responsenum>
<totalrequests><!--[CDATA[0]]--></totalrequests>
<totalcompleted><!--[CDATA[0]]--></totalcompleted>
</responsedata></item></methodresponse>

为了可读性而添加了换行符。

“没有通过 XML 数据”的响应文本让我感到担忧,因此我联系了供应商,并被告知要仔细检查我的信息。 URL(http 与 https,正确的 N in echo*N*.bluehornet... 等)并确保我使用“data”参数进行发布,建议放置“? data= 在 HTTP 标头中的查询 URL 末尾:

POST /api/xmlrpc/index.php?data= HTTP/1.0

或者在请求正文中的 XML 块前面添加“data=”:

data=<?xml version="1.0"?>

这似乎是为 .NET 姊妹项目编写的代码所暗示的:

private void ConstructData()
{
    data.Append("data=");
    data.Append("<api>");
    data.Append("<authentication>");
    data.Append(authenticationData.ToString());
    data.Append("</authentication>");
    data.Append("<data><methodCall>");
    data.Append(methodCallData.ToString());
    data.Append("</methodCall></data>");
    data.Append("</api>");
}

修改查询URL 没有效果,并且在 XML 块之前放置“data=”会导致加载时间延长,然后服务器没有响应。

此时,供应商正试图挖掘一位以前使用过该 API 的开发人员来权衡这个问题。同时,我想我应该分享以上内容,看看是否有人可以指出任何问题(可能是轻微的疏忽或明显的遗漏),这可能会导致我的 XML 数据无法发送。

I am working with the BlueHornet API for sending email, specifically the legacy.send_campaign method. I am updating a client's existing API calls and have been instructed to

"POST the XML message using the arguments specified below. Be sure to include the <send> element and set its value to 'Y'. The POST response message will include a <message_id> element and a <message_key> element.

This is the provided format:

<api>
    <authentication>
        <api_key>ClientAPIKey</api_key>
        <shared_secret>ClientSharedSecret</shared_secret>
        <response_type>xml</response_type>
    </authentication>
    <data>
        <methodCall>
            <methodName>legacy.send_campaign</methodName>
            <grp>ClientEmailGroupCode</grp>
            <rich_mbody><![CDATA[<html...LONG HTML BLOCK...</html>]]></rich_mbody>
            <text_mbody><![CDATA[...LONG TEXT BODY...]]></text_mbody>
            <reply_email>ClientReplyEmail</reply_email>
            <from_email>ClientFromEmail</from_email>
            <fromdesc>ClientFromName</fromdesc>
            <msubject>ClientEmailSubject</msubject>
            <send>Y</send>
            <track_links>1</track_links>
        </methodCall>
    </data>
</api>

The API is password protected, but I can post doc's upon request.

I have confirmed the ClientAPIKey, ClientSharedSecret, and ClientEmailGroupCode as valid, but my testing has been unsuccessful. Sending the following (using fsockopen() FWIW):

POST /api/xmlrpc/index.php HTTP/1.0
Host: echoN.bluehornet.com
Content-Type: text/xml;charset=utf-8
Content-Length: 21551

<?xml version="1.0"?>
<api>
    <authentication>...as above...</authentication>
    <data>...as above...</data>
</api>

causes the third-party server to send back this XML response indicating an error:

HTTP/1.1 200 OK
Date: Thu, 13 Oct 2011 13:18:50 GMT
Server: Apache/1.3.41 (Unix)
Cache-Control: max-age=18000
Expires: Thu, 13 Oct 2011 18:18:50 GMT
Connection: close
Content-Type: text/xml;charset=utf-8
Set-Cookie: BIGipServerBH-gen-80=387268618.20480.0000; path=/

<!--?xml version="1.0" encoding="utf-8"?-->
<methodresponse><item><error><!--[CDATA[1]]--></error>
<responsetext><!--[CDATA[No XML Data Passed.]]--></responsetext>
<responsedata><responsenum><!--[CDATA[1]]--></responsenum>
<totalrequests><!--[CDATA[0]]--></totalrequests>
<totalcompleted><!--[CDATA[0]]--></totalcompleted>
</responsedata></item></methodresponse>

Line breaks added for readability.

The responseText of "No XML Data Passed." concerned me, so I contacted the vendor and was told to double check my URL (http vs. https, correct N in echo*N*.bluehornet..., etc.) and to be sure I was posting with the "data" parameter. Suggestions were to place "?data=" at the end of the query URL in the HTTP header:

POST /api/xmlrpc/index.php?data= HTTP/1.0

or to prepend "data=" to the XML block in the request body:

data=<?xml version="1.0"?>

which seems to be implied by the code written for a .NET sister project:

private void ConstructData()
{
    data.Append("data=");
    data.Append("<api>");
    data.Append("<authentication>");
    data.Append(authenticationData.ToString());
    data.Append("</authentication>");
    data.Append("<data><methodCall>");
    data.Append(methodCallData.ToString());
    data.Append("</methodCall></data>");
    data.Append("</api>");
}

Modifying the query URL had no effect, and placing "data=" before the XML block caused a prolonged load time followed by no server response.

At this point, the vendor is trying to dig up a developer who has used the API before to weigh in on the issue. In the meantime, I thought I'd share the above and see if anyone could point out any issues – minor oversights or glaring omissions as they may be – which might be causing my XML data not to be sent.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

相对绾红妆 2024-12-17 04:46:50

如果帖子确实应该看起来像 data=xxx ,那么您可能应该使用此标头

Content-Type: application/x-www-form-urlencoded

和帖子正文发送帖子数据,好吧,网址编码:)

If post really should look like data=xxx than you should probably send post data with this header

Content-Type: application/x-www-form-urlencoded

And with post body, well, url encoded :)

我的黑色迷你裙 2024-12-17 04:46:50

这有效。来到这里真是太糟糕了。最后意识到 ?data= 是传递有效负载的字段。

import urllib

from google.appengine.api import urlfetch

url = "https://echoN.bluehornet.com/api/xmlrpc/index.php"


    XML="""<api>
    <authentication>
    <api_key>000000000000000000</api_key>
    <shared_secret>00000000</shared_secret>
    <response_type>xml</response_type>
    </authentication>
    <data>
    <methodCall>
    <methodName>legacy.retrieve_active</methodName>
    <email>[email protected]</email>
    <return_groups>1</return_groups>
    </methodCall>
    </data>
    </api>"""


form_fields = {'data': XML}
form_data = urllib.urlencode(form_fields)

result = urlfetch.fetch(url=url,
                        payload=form_data,
                        method=urlfetch.POST,
                        headers={'Content-Type': 'application/x-www-form-urlencoded'})

print result.content

This works. Was hell of a time getting here. Finally realized the ?data= was the field to pass in the payload.

import urllib

from google.appengine.api import urlfetch

url = "https://echoN.bluehornet.com/api/xmlrpc/index.php"


    XML="""<api>
    <authentication>
    <api_key>000000000000000000</api_key>
    <shared_secret>00000000</shared_secret>
    <response_type>xml</response_type>
    </authentication>
    <data>
    <methodCall>
    <methodName>legacy.retrieve_active</methodName>
    <email>[email protected]</email>
    <return_groups>1</return_groups>
    </methodCall>
    </data>
    </api>"""


form_fields = {'data': XML}
form_data = urllib.urlencode(form_fields)

result = urlfetch.fetch(url=url,
                        payload=form_data,
                        method=urlfetch.POST,
                        headers={'Content-Type': 'application/x-www-form-urlencoded'})

print result.content
热风软妹 2024-12-17 04:46:50

当我删除标题行时它起作用:

//curl_setopt($ch, CURLOPT_HTTPHEADER, ...

最终代码:

curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('data' => $xml));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);

It works when I removed the header line:

//curl_setopt($ch, CURLOPT_HTTPHEADER, ...

Final code:

curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('data' => $xml));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
虫児飞 2024-12-17 04:46:50

让它工作的唯一方法是 POST XML 作为字节数组,内容类型=“application/x-www-form-urlencoded”

the only way to get it working is POST XML as byte array with content-type = "application/x-www-form-urlencoded"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文