未收到 PHP 中通过 POST 发送的 XML
我正在使用 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 受密码保护,但我可以根据请求发布文档。
我已确认 ClientAPIKey, ClientSharedSecret 和 ClientEmailGroupCode 有效,但我的测试不成功发送以下内容(使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果帖子确实应该看起来像 data=xxx ,那么您可能应该使用此标头
和帖子正文发送帖子数据,好吧,网址编码:)
If post really should look like data=xxx than you should probably send post data with this header
And with post body, well, url encoded :)
这有效。来到这里真是太糟糕了。最后意识到 ?data= 是传递有效负载的字段。
This works. Was hell of a time getting here. Finally realized the ?data= was the field to pass in the payload.
当我删除标题行时它起作用:
最终代码:
It works when I removed the header line:
Final code:
让它工作的唯一方法是 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"