curl_basic_003.phpt 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. --TEST--
  2. Test curl_opt() function with POST parameters
  3. --CREDITS--
  4. Sebastian Deutsch <sebastian.deutsch@9elements.com>
  5. TestFest 2009 - AFUP - Jean-Marc Fontaine <jmf@durcommefaire.net>
  6. --SKIPIF--
  7. <?php include 'skipif.inc'; ?>
  8. --FILE--
  9. <?php
  10. /* Prototype : bool curl_setopt(resource ch, int option, mixed value)
  11. * Description: Set an option for a cURL transfer
  12. * Source code: ext/curl/interface.c
  13. * Alias to functions:
  14. */
  15. include 'server.inc';
  16. $host = curl_cli_server_start();
  17. // start testing
  18. echo '*** Testing curl sending through GET an POST ***' . "\n";
  19. $url = "{$host}/get.php?test=getpost&get_param=Hello%20World";
  20. $ch = curl_init();
  21. ob_start(); // start output buffering
  22. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  23. curl_setopt($ch, CURLOPT_POST, 1);
  24. curl_setopt($ch, CURLOPT_POSTFIELDS, "Hello=World&Foo=Bar&Person=John%20Doe");
  25. curl_setopt($ch, CURLOPT_URL, $url); //set the url we want to use
  26. $curl_content = curl_exec($ch);
  27. curl_close($ch);
  28. var_dump( $curl_content );
  29. ?>
  30. ===DONE===
  31. --EXPECTF--
  32. *** Testing curl sending through GET an POST ***
  33. string(208) "array(2) {
  34. ["test"]=>
  35. string(7) "getpost"
  36. ["get_param"]=>
  37. string(11) "Hello World"
  38. }
  39. array(3) {
  40. ["Hello"]=>
  41. string(5) "World"
  42. ["Foo"]=>
  43. string(3) "Bar"
  44. ["Person"]=>
  45. string(8) "John Doe"
  46. }
  47. "
  48. ===DONE===