1. <?php
  2. //
  3. // A very simple PHP example that sends a HTTP POST to a remote site
  4. //
  5.  
  6. $ch = curl_init();
  7. $body = array('userName'=>'15555555555','password'=>'111111');
  8. $postData = http_build_query($body);
  9.  
  10. curl_setopt($ch, CURLOPT_URL,"http://xxxxxxxx.xxx/xx/xx");
  11. curl_setopt($ch, CURLOPT_POST, 1);
  12. curl_setopt($ch, CURLOPT_POSTFIELDS,$postData);
  13. curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
  14.  
  15.  
  16. // receive server response ...
  17. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  18.  
  19. $server_output = curl_exec ($ch);
  20.  
  21. curl_close ($ch);
  22.  
  23. // further processing ....
  24. if ($server_output == "OK") { ... } else { ... }
  25.  
  26. ?>

来源:https://stackoverflow.com/questions/18913345/curl-posting-with-header-application-x-www-form-urlencoded

作者 铁血 汉子 2022年4月13日
2025/04/07/12:29:07am 2022/4/13/5:45:39
0 893