【问题标题】:How to make GET and POST requests with socket_create() and custom headers?如何使用 socket_create() 和自定义标头发出 GET 和 POST 请求?
【发布时间】:2012-01-20 20:36:00
【问题描述】:

我正在编写一个需要与服务 REST API 接口通信的 PHP 脚本,我只能访问 socket_create(),socket_connect(),socket_write(),socket_read() 而没有 cURL!

我需要使用他们用来验证和跟踪我的应用程序的自定义标头发出请求,并且在发送 POST 请求时,发布数据是一个 json 编码字符串(这让我感到困惑,因为我使用 key1=value1&key2= 发出 POST 请求value2 像参数)。在 POST 请求的情况下,您能帮我找到一些带有自定义标头和 json 数据的 GET 和 POST 请求示例吗?

感谢您的帮助,

斯蒂芬

【问题讨论】:

    标签: php sockets rest restful-authentication


    【解决方案1】:

    我认为你最好使用 php 中的 fsockopen http://php.net/manual/en/function.fsockopen.php 否则你可以使用 TinyHttpClient 库 http://henryranch.net/software/php-http-socket-client/

    【讨论】:

      猜你喜欢
      • 2015-01-18
      • 1970-01-01
      • 2017-06-20
      • 2014-03-10
      • 1970-01-01
      • 1970-01-01
      • 2017-08-09
      • 2013-01-24
      • 1970-01-01
      相关资源
      最近更新 更多