Solved

Symfony2 > Accept incomming XML connection

Posted on 2014-01-27
2
60 Views
Last Modified: 2016-05-17
I am busy implementing a third-party credit card payment API (paygate.co.za payXML) and the API submits an XML string to a URL that I specify, which I have set up to a route that calls a Controller function. I am not sure exactly how the API sends the XML string back, but it does not look like it is a normal POST.

Inside the controller function (which I have set up to catch the XML post) I have a set a up a test that writes "TEST" to a file. When I run the controller function manually by browsing the the route, then "TEST" gets written to the file. However, when I try to execute the controller function by initiating a curl_exec() to the route (submitting an XML string) nothing happens, the file remains blank so I am assuming that the controller function does not execute.

I have ensured that the URL I am submitting to via cURL is correct. I have also ensured that the route is not behind a firewall and is publically accessible without requiring authentication.

curl_error($oCurl); is empty and when I try print curl_exec($oCurl); the controller function [in which I execute the curl_exec()] never stops running.

Code extract from the controller function (which attempts to execute the other controller function by initiating a cURL connection to its route):

$url = "http://localhost:90/pmb/web/app_dev.php/payNotify";

$xml = <<<XML
<?xml version="1.0" encoding="utf-8"?>  
<test>
    <subtest id="test">Test</subtest>
</test>
XML;

    $headers = array(
        "Content-type: text/xml",
        "Content-length: " . strlen($xml),
        "Connection: close",
    );

    $oCurl = curl_init(); 
    curl_setopt($oCurl, CURLOPT_URL,$url);
    curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, false); 
    curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($oCurl, CURLOPT_TIMEOUT, 120);
    curl_setopt($oCurl, CURLOPT_POST, 1);
    curl_setopt($oCurl, CURLOPT_POSTFIELDS, $xml);
    curl_setopt($oCurl, CURLOPT_HTTPHEADER, $headers);

    $response = curl_exec($oCurl); 
    if(curl_errno($oCurl))
        print curl_error($oCurl);
    else
        curl_close($oCurl);
    die("Testing");

Open in new window


Is there anything that I need to set up and in Symfony in order to accept a connection of this nature and route it to the required Controller function? Also, after I have succeeded in getting my Controller function to accept the connection? How would I access the incomming XML string?
0
Comment
Question by:Magnanimity0
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 40100043
I suspect you need to read the data from php://input - refer to:
http://www.php.net/manual/en/reserved.variables.httprawpostdata.php#94584

If problems persist, try  "Content-type: text/plain" instead.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question