【问题标题】:How to call an URL with php without redirect如何在没有重定向的情况下使用 php 调用 URL
【发布时间】:2014-02-12 09:38:48
【问题描述】:

我正在使用 URL 将参数传输到远程位置。 我需要使用 PHP 调用 URL - 无需重定向到 URL。

我尝试了不同的解决方案,但没有运气。在处理 PHP 时,我远不是专家,我什至不确定我是否正确地措辞。

我试过了:

$curl = curl_init();
curl_setopt ($curl, CURLOPT_URL, "https://remotelocation.com/storedata.aspx?name=".$name."&email=".$email_address.);
curl_exec ($curl);
curl_close ($curl);

和:

file_get_contents("https://remotelocation.com/storedata.aspx?name=".$name."&email=".$email_address.")

运气不好。

在浏览器中手动调用 URL(使用确定的值而不是变量)存储数据。使用 mail() 代替,数据也被传输。

我知道解决方案一定很简单。谁能帮我指出正确的方向?

【问题讨论】:

  • 您确定问题不在于您可能在name 之后缺少等号吗? (例如file_get_contents("https://remotelocation.com/storedata.aspx?name=".$name."&email=".$email_address.")
  • 您在姓名后面缺少=。还是打错字了?
  • 对不起..这是一个错字。重写问题的链接时忘记了...“=”包含在测试代码中。

标签: php curl parameters file-get-contents


【解决方案1】:

不知道为什么它不适用于file_get_contents。但是对于 curl 还需要添加以下几个选项(其实有很多,可以到here查看)。

// to handle https links
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);

// return response
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

并获取返回的响应html

$response_html = curl_exec ($curl);

【讨论】:

    猜你喜欢
    • 2011-09-28
    • 1970-01-01
    • 1970-01-01
    • 2013-04-01
    • 1970-01-01
    • 2011-05-02
    • 2014-08-27
    • 2012-10-21
    • 2014-08-03
    相关资源
    最近更新 更多