Jump to:

23368 Posts in 18143 Topics by 2863 members

General Questions

SilverStripe Forums » General Questions » Sending an XML file using SS_HTTPRequest

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1068 Views
  • TDNP
    Avatar
    Community Member
    19 Posts

    Sending an XML file using SS_HTTPRequest Link to this post

    I've created a form that is a gateway to an online payment center that my employer uses to receive donations. The form is supposed to find out how the donor would like to pay, gather the necessary details, write those details to an XML file and then send the XML file to an external URL. So far, the form does the first three steps perfectly. I cannot get the file to send and if it is sending, I cannot get the response from their server to populate my getBody() function.

    I've gone through many different steps and most recently I am getting the error:
    Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 8388608 bytes) in C:\xampp\htdocs\pnwu\sapphire\core\control\HTTPRequest.php on line 33

    Am I over-thinking this? Is there a simple way to just post this XML file to the URL? Any suggestions would be great. Also if you have successfully sent an XML file from SS, I'd love to know how you accomplished it.

  • MarcusDalgren
    Avatar
    Community Member
    288 Posts

    Re: Sending an XML file using SS_HTTPRequest Link to this post

    Can't you just send the XML as a string instead of trying to save it to a file and sending that?
    Other gateways I've worked with allowed the XML to be sent in such a fashion.

  • TDNP
    Avatar
    Community Member
    19 Posts

    Re: Sending an XML file using SS_HTTPRequest Link to this post

    Do you mean as a part of the URL?

    i.e. https://webpage/example.asmx?appID=xxxx&skinID=xxxx

  • MarcusDalgren
    Avatar
    Community Member
    288 Posts

    Re: Sending an XML file using SS_HTTPRequest Link to this post

    No I was rather thinkíng about using cURL to post the data to them if that's what they want.
    If you're using cURL to do a post you're going to need some kind of key though.

    Are you contacting them directly or are they contacting an URL on your server and expecting an XML response?
    If the latter I would try just outputting the XML directly to the screen.

  • TDNP
    Avatar
    Community Member
    19 Posts

    Re: Sending an XML file using SS_HTTPRequest Link to this post

    I am contacting them directly. Using cURL could be an option. Is it native in SS?

  • MarcusDalgren
    Avatar
    Community Member
    288 Posts

    Re: Sending an XML file using SS_HTTPRequest Link to this post

    No cURL is native to PHP if you're on a decent host. Looking through SS_HTTPRequest it seems that this class is only for parsing and working with the site URL for SilverStripe and not handling external URL:s. I think cURL might be your best option if that's the kind of thing you need to do.

    If you need to send a file try this: http://dtbaker.com.au/random-bits/uploading-a-file-using-curl-in-php.html

  • TDNP
    Avatar
    Community Member
    19 Posts

    Re: Sending an XML file using SS_HTTPRequest Link to this post

    I have tried the cURL approach and I don't get any errors but I'm not being redirected to the URL I'm giving it. That is the endgame in this scenario. To be sent with my XML file (or string) to the destination URL.

  • MarcusDalgren
    Avatar
    Community Member
    288 Posts

    Re: Sending an XML file using SS_HTTPRequest Link to this post

    Ok so there's supposed to be a redirect after sending the file and not a separate request from their server to the URL you specify?
    Could you maybe link the specs so I could read them?

    You can try setting

    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);

    And cURL should follow any redirects and return the results from them. Dump the $response variable to find out what kind of response you're getting.

    1068 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.