MultiRequestService multiPost($urls)


  • 用法
    基于GuzzleHttp的并发POST请求。

MultiRequestService对象方法列表:

  • concurrency():设置并发数
  • withOptions():设置GuzzleHttp的一些其他选项
  • withHeaders(): 设置HTTP Header
  • success(): HTTP success回调函数
  • error(): HTTP error回调函数
  • send(): 发送请求

用法

用法同multiGet().

  1. use GuzzleHttp\Psr7\Response;
  2. use QL\QueryList;
  3. $requests = [
  4. new Request('POST','http://httpbin.org/post',[
  5. 'Content-Type' => 'application/x-www-form-urlencoded',
  6. 'User-Agent' => 'g-http'
  7. ],http_build_query([
  8. 'name' => 'php'
  9. ])),
  10. new Request('POST','http://httpbin.org/post',[
  11. 'Content-Type' => 'application/x-www-form-urlencoded',
  12. 'User-Agent' => 'g-http'
  13. ],http_build_query([
  14. 'name' => 'go'
  15. ])),
  16. new Request('POST','http://httpbin.org/post',[
  17. 'Content-Type' => 'application/x-www-form-urlencoded',
  18. 'User-Agent' => 'g-http'
  19. ],http_build_query([
  20. 'name' => 'c#'
  21. ]))
  22. ];
  23. QueryList::multiPost($requests)
  24. ->success(...)
  25. ->send();