Ik tracht een HTTP POST mbv PHP te doen met de volgende functie:
Deze functie heb ik gevonden en ik begrijp hoe deze werkt.
Om de functie te testen POST ik naar een PHP script op een lokale IIS server.
Ik krijg nu steeds echter als response error 405 terug:
HTTP/1.1 100 Continue
Server: Microsoft-IIS/4.0
Date: Tue, 01 Apr 2003 07:40:06 GMT
HTTP/1.1 405 Method not allowed
Server: Microsoft-IIS/4.0
Date: Tue, 01 Apr 2003 07:40:06 GMT
Connection: close
Allow: OPTIONS, TRACE, GET, HEAD, PUT, DELETE
Content-Length: 545
Content-Type: text/html
Ik heb nagezocht wat die error betekent en dit komt bijv. voor als je wilt gaan posten naar een html file of iets dergelijks wat natuurlijk niet toegestaan is.
Ik post echter naar een PHP script dus dit zou moeten werken.
Mankeert er wellicht iets aan het POST request
PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
| /* sendToHost * ~~~~~~~~~~ * Params: * $host - Just the hostname. No http:// or /path/to/file.html portions * $method - get or post, case-insensitive * $path - The /path/to/file.html part * $data - The query string, without initial question mark * * Examples: * sendToHost('www.google.com','get','/search','q=php_imlib'); * sendToHost('www.example.com','post','/some_script.cgi', * 'param=First+Param&second=Second+param'); */ function sendToHost($host, $method, $path, $data) { $method = strtoupper($method); $fp = fsockopen($host, 80, $errno, $error, 30); if (!$fp) { echo 'Error number=' . $errno . '<br>'; echo 'Error=' . $error . '<br>'; return(''); } if ($method == 'GET') { $path .= '?' . $data; } fputs($fp, "$method $path HTTP/1.1\n"); fputs($fp, "Host: $host\n"); fputs($fp, "Content-type: application/x-www-form-urlencoded\n"); fputs($fp, "Content-length: " . strlen($data) . "\n"); fputs($fp, "User-Agent: MSIE\n"); fputs($fp, "Connection: close\n\n"); if ($method == 'POST') { fputs($fp, $data); } $buf = ''; while (!feof($fp)) { $buf .= fgets($fp, 128); } fclose($fp); return $buf; } |
Deze functie heb ik gevonden en ik begrijp hoe deze werkt.
Om de functie te testen POST ik naar een PHP script op een lokale IIS server.
PHP:
1
| $response = sendToHost('192.168.100.3', 'POST', '/post_test.php', 'test=blaat'); |
Ik krijg nu steeds echter als response error 405 terug:
HTTP/1.1 100 Continue
Server: Microsoft-IIS/4.0
Date: Tue, 01 Apr 2003 07:40:06 GMT
HTTP/1.1 405 Method not allowed
Server: Microsoft-IIS/4.0
Date: Tue, 01 Apr 2003 07:40:06 GMT
Connection: close
Allow: OPTIONS, TRACE, GET, HEAD, PUT, DELETE
Content-Length: 545
Content-Type: text/html
Ik heb nagezocht wat die error betekent en dit komt bijv. voor als je wilt gaan posten naar een html file of iets dergelijks wat natuurlijk niet toegestaan is.
Ik post echter naar een PHP script dus dit zou moeten werken.
Mankeert er wellicht iets aan het POST request
It’s nice to be important but it’s more important to be nice