Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

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

Sending an XML file using SS_HTTPRequest


Reply


8 Posts   1181 Views

Avatar
TDNP

Community Member, 19 Posts

11 January 2012 at 8:45am

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.

Avatar
MarcusDalgren

Community Member, 288 Posts

11 January 2012 at 8:52am

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.

Avatar
TDNP

Community Member, 19 Posts

11 January 2012 at 10:48am

Do you mean as a part of the URL?

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

Avatar
MarcusDalgren

Community Member, 288 Posts

11 January 2012 at 11:05am

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.

Avatar
TDNP

Community Member, 19 Posts

11 January 2012 at 11:40am

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

Avatar
MarcusDalgren

Community Member, 288 Posts

11 January 2012 at 12:02pm

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: [url]http://dtbaker.com.au/random-bits/uploading-a-file-using-curl-in-php.html[/url]

Avatar
TDNP

Community Member, 19 Posts

12 January 2012 at 8:17am

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.

Avatar
MarcusDalgren

Community Member, 288 Posts

12 January 2012 at 9:00am

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.