【问题标题】:How do I cURL to this type of URL in PHP [192.168.1.30:8080/server]?如何在 PHP [192.168.1.30:8080/server] 中 cURL 到这种类型的 URL?
【发布时间】:2016-09-14 08:21:16
【问题描述】:

我知道您可以使用 CURLOPT_PORT 指定端口号,但是服务器托管在端口号后面的目录中。如果 cURL 无法做到这一点,是否有一种方法可以让我将表单数据发布到我上面指定的 URL 格式?请帮忙。

【问题讨论】:

    标签: php http curl post port


    【解决方案1】:

    是的,您只需要指定CURLOPT_PORT 并在您的网址中省略端口,例如:

    <?php
    $post = [
        'field' => 'value',
    ];
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'http://192.168.1.30/server');
    curl_setopt($ch,CURLOPT_PORT, 8080);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
    $response = curl_exec($ch);
    if ($response === false) {
        throw new RuntimeException(curl_error($ch));
    }
    var_export($response);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-07
      • 2011-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-02
      相关资源
      最近更新 更多