Note that there are some explanatory texts on larger screens.

plurals
  1. POUse PHP to post XML via cURL without first generating XML file
    text
    copied!<p>I am trying to send an XML file via POST to a form on a remote server. I am generating the XML data on the fly, and storing it as a string in a variable called $XmlData. This is a string starting with my opening tag (see example below)...so no "headers" are in this string. I could easily write it to the server in a temp directory as an XML file...but ideally i want to just post this as if it were a file, but without the added step of creating the file (which i would then have to delete afterwords)... Below is the code that i THINK should allow me to upload my XML file if i actually created it first...</p> <pre><code> $url = 'http://www.mydomain.com/path/to/form/process.php'; $ch = curl_init($url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_VERBOSE, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)"); curl_setopt($ch, CURLOPT_URL, _VIRUS_SCAN_URL); curl_setopt($ch, CURLOPT_POST, true); // same as &lt;input type="file" name="xmlfileresource"&gt; $post = array( "xmlfileresource"=&gt;"@/path/to/myfile.xml", "action"=&gt;"incomingXml", "user"=&gt;"JohnSmith", ); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); $response = curl_exec($ch); curl_close($ch); </code></pre> <p>My question is this: How can I stream/blob/whatever the content of my $XmlData string into this cURL execution such that the remote server thinks it was just a normal file being POSTed?</p> <p>Not really relevant, but in case it helps...my $XmlData string might look something like this:</p> <pre><code>&lt;clientversion&gt; &lt;component&gt; &lt;type&gt;module&lt;/type&gt; &lt;name&gt;resources&lt;/name&gt; &lt;version&gt;2.7.3&lt;/version&gt; &lt;date&gt;2012-09-01 02:18:33&lt;/date&gt; &lt;/component&gt; &lt;component&gt; &lt;type&gt;module&lt;/type&gt; &lt;name&gt;staff&lt;/name&gt; &lt;version&gt;3.1&lt;/version&gt; &lt;date&gt;2011-04-01 07:12:48&lt;/date&gt; &lt;/component&gt; &lt;/clientversion&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload