0

I want to submit POST data using the DOMDocument class (DOMDocument::loadHTMLFile() to be precise) to simulate a html form using the post method being submitted.

For that purpose I tried to set my params using stream_context_set_default() but somehow that won't work:

<?php
$default_opts = array(
  'http'=>array(
     'method'=>"GET",
     'header'=>"Accept-language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3",
     'content'=>'param=value'
   )
);
stream_context_set_default($default_opts);

$doc = new DOMDocument();
$doc->loadHTMLFile('http://127.168.2.1/path/to/file/test_post.php');

echo $doc->saveXML();
?>

Am I missing something or is there simply no way to do that? If so, is there another way to do that with the DOMDocument class or do i have to use another mechanism like curl or fsockopen()?

Anticom
  • 975
  • 13
  • 29
  • 1
    *(hint)* you are using method="GET" – Gordon Oct 11 '11 at 09:57
  • *(reference)* http://docs.php.net/manual/en/function.libxml-set-streams-context.php – Gordon Oct 11 '11 at 09:59
  • yeah, because the http request itself has got to be GET, doesn't it? – Anticom Oct 11 '11 at 11:01
  • [why should it have to be GET when you want to do a POST request?](https://secure.wikimedia.org/wikipedia/en/wiki/Hypertext_Transfer_Protocol) – Gordon Oct 11 '11 at 11:11
  • but changing method to POST obviously does not solve my problem – Anticom Oct 11 '11 at 12:18
  • odd, because unless you are not adequately describing your problem my first two comments contain everything you need to make it work. – Gordon Oct 11 '11 at 12:27
  • As i already said in the description, I want to simulate submitting POST data, just as if a user would click the submit button in a form using method='post'. Due to that the HTTP request does not essentially have to be method post aswell, does it? However I'd like to find a solution doing exactly that using the DOMDocument class. I've found a solution using curl already but that would unfortunately mess up my whole class hierarchy :( – Anticom Oct 12 '11 at 09:24
  • well, like I said, my first two comments contain all the pointers you need to do POST request with DOM. – Gordon Oct 12 '11 at 09:39

0 Answers0