将php函数curl_init()转换为coldfusion

时间:2015-11-11 16:19:01

标签: coldfusion

我需要将此代码PHP转换为coldfusion: 有嗡嗡声参数xml什么是必要的消费参数是

<?php

$_string = '<SPCA-XML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.scpc.inf.br/spcn/spcaxml.xsd">
    <VERSAO>20131120</VERSAO>
    <SOLICITACAO>
        <S-CODIGO>2122</S-CODIGO>
        <S-SENHA>5454</S-SENHA>
        <S-CONSULTA>4545</S-CONSULTA>
        <S-SOLICITANTE>XXXXXX</S-SOLICITANTE>
        <S-CPF>2222222</S-CPF>
        <S-TIPO-CREDITO>CD</S-TIPO-CREDITO>
    </SOLICITACAO>
</SPCA-XML>';

$_post = curl_init();
curl_setopt($_post, CURLOPT_URL, "https://www.scpc.inf.br/cgi-bin/spcaxml");
curl_setopt($_post, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($_post, CURLOPT_POSTFIELDS, $_string);
curl_setopt($_post, CURLOPT_RETURNTRANSFER, 1);
$_result = curl_exec($_post);
curl_close($_post);

header("Content-type: text/xml");
echo $_result;

?>

1 个答案:

答案 0 :(得分:1)

你可以这样做:

<cfsavecontent variable="xmlString">
    <SPCA-XML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.scpc.inf.br/spcn/spcaxml.xsd">
        <VERSAO>20131120</VERSAO>
        <SOLICITACAO>
            <S-CODIGO>2122</S-CODIGO>
            <S-SENHA>5454</S-SENHA>
            <S-CONSULTA>4545</S-CONSULTA>
            <S-SOLICITANTE>XXXXXX</S-SOLICITANTE>
            <S-CPF>2222222</S-CPF>
            <S-TIPO-CREDITO>CD</S-TIPO-CREDITO>
        </SOLICITACAO>
    </SPCA-XML>'
</cfsavecontent>
<cfhttp url="https://www.scpc.inf.br/cgi-bin/spcaxml" method="post" result="result">
    <cfhttpparam type="header" name="Content-Type" value="text/xml" />
    <cfhttpparam type="xml" value="#xmlString#" />
</cfhttp>
<cfdump var="#result#">

以下是响应的cfdump: enter image description here

有关代码的更多信息,请浏览@James A Mohler建议的链接。