I need to POST some XML data to a remote server for processing. The server protocol is already defined and unchangeable. The XML data I want to post is dynamically generated within a PHP page running on a local server. I do not want the user to have to save that XML data to a file and then browse for the file to upload it to the remote server (this would not be user-friendly and pointless). My question is how to do this using PHP functions (it would be possible to do it by coding an HTML form with an ‘input file=’ field, but this means that the user has to browse for the file). I have been given an example, and what I need is to write PHP code that will exactly reproduce the headers in the example and send it to the remote server. Any clues to help me?
POST http://doi.crossref.org/servlet/deposit? operation=doMDUpload&login_id=USER&login_passwd=PSWD&area=live HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*
Accept-Language: en-us Content-Type: multipart/form-data; boundary=---------------------------7d22911b10028e
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Q312461)
Host: Myhost
Content-length: 1304 Pragma: no-cache -----------------------------7d22911b10028e
Content-Disposition: form-data; name="fname"; filename="crossref_query.xml"
<?xml version="1.0" encoding="UTF-8"?>
.....XML data....
-----------------------------7d22911b10028e--
Things I have tried without success: a form and a input=hidden field for the XML data (the POSTed data does not include a filename and so is rejected by the remote server); http_post_data() – just gave me an internal server error at the remote server; hand coding the data stream and sending it through a a port 80 socket after using fopensocket – the server didn’t recognise that the stream contained POSTed form data, even after checking the stream I sent, character by character using tcpdump. So as you can tell, I’m getting desperate!
from here…