如何通过 HTTP POST 将 XML 消息发送到测试 URL?

请注意,我是初学者,仍在学习 javascript 和后端概念。


我有一个 HTML 表单,用于收集用户信息并在提交时通过验证并转换为 XML。我让它在控制台中作为对象的位置工作并输出以下代码,但是:


我需要做的是通过 HTTP POST 将该 XML 发送到测试 URL 并获得响应。


我的测试网址是https://plmdemo.infinityels.com/plm.net/lead/xml/Processor.ashx


我不知道从哪里开始。


该 URL 需要这样的 XML:


<LeadRequest>

    <Username>test</Username>

    <Password>test</Password>

    <FirstName>Bill</FirstName>

    <LastName>Jones</LastName>

    <SSN>sdf</SSN>

    <Gender>F</Gender>

    <Email>sdf@gmail.com</Email>

    <DOB>2018-07-22</DOB>

    <DriversLicense>sdf</DriversLicense>

    <DriversLicenseState>sdf</DriversLicenseState>

    <HomeAddress>sdf</HomeAddress>

    <HomeCity>sdf</HomeCity>

    <HomeState>AL</HomeState>

    <HomeZip>sdf</HomeZip>

    <TimeAtAddress>3</TimeAtAddress>

    <HomePhone>123-456-7890</HomePhone>

    <WorkPhone>123-456-7890</WorkPhone>

    <CellPhone>123-456-7890</CellPhone>

    <BankInfo>

        <BankName>Citi</BankName>

        <BankPhone>123-456-7890</BankPhone>

        <AbaNumber>1</AbaNumber>

        <CheckingAccount>2</CheckingAccount>

        <SavingsAccount>2</SavingsAccount>

        <AccountToUse>C</AccountToUse>

        <AccountLength>2</AccountLength>

    </BankInfo>

    <EmploymentInfo>

        <MonthlyIncome>12</MonthlyIncome>

        <PayFrequency>1</PayFrequency>

        <IncomeType>1</IncomeType>

        <PayrollType>1</PayrollType>

        <NextPayDay>2019-09-12</NextPayDay>

        <SecondNextPayDay>2019-09-26</SecondNextPayDay>

        <Employer>sdf</Employer>

        <Occupation>sdf</Occupation>

        <EmploymentLength>2</EmploymentLength>

        <Phone>123-456-7890</Phone>

    </EmploymentInfo>

    <LoanInfo>

        <Amount>300</Amount>

        <DueDate>2019-10-18</DueDate>

    </LoanInfo>

</LeadRequest>


白衣染霜花
浏览 139回答 1
1回答

慕桂英3389331

我能够得到一些有用的错误消息。我编辑了 SSN,该错误消失了。<?phperror_reporting(E_ALL);ini_set('display_errors', true);$xml = '<?xml version="1.0"?><LeadRequest><Username>test</Username><Password>test</Password><FirstName>Bill</FirstName><LastName>Jones</LastName><SSN>sdf</SSN><Gender>F</Gender><Email>sdf@gmail.com</Email><DOB>2018-07-22</DOB><DriversLicense>sdf</DriversLicense><DriversLicenseState>sdf</DriversLicenseState><HomeAddress>sdf</HomeAddress><HomeCity>sdf</HomeCity><HomeState>AL</HomeState><HomeZip>sdf</HomeZip><TimeAtAddress>3</TimeAtAddress><HomePhone>123-456-7890</HomePhone><WorkPhone>123-456-7890</WorkPhone><CellPhone>123-456-7890</CellPhone><BankInfo><BankName>Citi</BankName><BankPhone>123-456-7890</BankPhone><AbaNumber>1</AbaNumber><CheckingAccount>2</CheckingAccount><SavingsAccount>2</SavingsAccount><AccountToUse>C</AccountToUse><AccountLength>2</AccountLength></BankInfo><EmploymentInfo><MonthlyIncome>12</MonthlyIncome><PayFrequency>1</PayFrequency><IncomeType>1</IncomeType><PayrollType>1</PayrollType><NextPayDay>2019-09-12</NextPayDay><SecondNextPayDay>2019-09-26</SecondNextPayDay><Employer>sdf</Employer><Occupation>sdf</Occupation><EmploymentLength>2</EmploymentLength><Phone>123-456-7890</Phone></EmploymentInfo><LoanInfo><Amount>300</Amount><DueDate>2019-10-18</DueDate></LoanInfo></LeadRequest>';$opts = array('http' =>&nbsp; &nbsp; array(&nbsp; &nbsp; &nbsp; &nbsp; 'method'&nbsp; => 'POST',&nbsp; &nbsp; &nbsp; &nbsp; 'header'&nbsp; => 'Content-Type: application/x-www-form-urlencoded',&nbsp; &nbsp; &nbsp; &nbsp; 'content' => $xml&nbsp; &nbsp; ));$context&nbsp; = stream_context_create($opts);$result = file_get_contents('https://plmdemo.infinityels.com/plm.net/lead/xml/Processor.ashx', false, $context);var_dump($result);
打开App,查看更多内容
随时随地看视频慕课网APP