【问题标题】:PHP cURL how to check if my request was blocked?PHP cURL 如何检查我的请求是否被阻止?
【发布时间】:2017-10-24 17:01:48
【问题描述】:

我在这个 asmx URL 上使用 cURL:http://ltcmobile.webhop.biz:2016/ereloadws/service.asmx 在本地主机中成功,但是当我将文件上传到我的实时服务器时,它将返回 bool(false)

但是我尝试将提交 URL 和我的请求更改为其他 asmx URL,我尝试了http://www.webservicex.net/globalweather.asmx,它确实可以在本地主机和实时服务器上运行。

这是否意味着我的连接被http://ltcmobile.webhop.biz:2016/ereloadws/service.asmx 阻止了?无论如何我可以检查并确认这一点?

curl_getinfo 结果:

本地主机: 数组 ( [url] => http://ltcmobile.webhop.biz:2016/ereloadws/service.asmx [content_type] => text/xml; charset=utf-8 [http_code] => 200 [header_size] => 230 [request_size] => 525 [filetime] => -1 [ ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0.109 [namelookup_time] => 0 [connect_time] => 0.063 [pretransfer_time] => 0.063 [size_upload] => 393 [size_download] => 479 [speed_download] => 4394 [speed_upload] => 3605 [download_content_length] => 479 [upload_content_length] => 393 [starttransfer_time] => 0.109 [redirect_time] => 0 [redirect_url] => [primary_ip] => 175.139.27.203 [certinfo] = > 数组 () [primary_port] => 2016 [local_ip] => 192.168.1.102 [local_port] => 52286)

实时服务器: 数组 ( [url] => http://ltcmobile.webhop.biz:2016/ereloadws/service.asmx [content_type] => [http_code] => 0 [header_size] => 0 [request_size] => 0 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] = > 0 [total_time] => 0 [namelookup_time] => 9.7E-5 [connect_time] => 0 [pretransfer_time] => 0 [size_upload] => 0 [size_download] => 0 [speed_download] => 0 [speed_upload] => 0 [download_content_length] => -1 [upload_content_length] => -1 [starttransfer_time] => 0 [redirect_time] => 0 [redirect_url] => [primary_ip] => 175.139.27.203 [certinfo] => 数组 ( ) )

卷发:

$xml_data = '<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
   <SendRequest xmlns="http://tempuri.org/">
     <ResellerAccount>*******</ResellerAccount>
     <RefNum>******</RefNum>
   </SendRequest>
</soap:Body>
</soap:Envelope>';

$URL = "http://ltcmobile.webhop.biz:2016/ereloadws/service.asmx";

$ch = curl_init($URL);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml; charset=utf-8'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);

var_dump($output);

提前致谢!

【问题讨论】:

  • 可能有很多原因。开始调查的一个好点是实际查看可用的 curl 信息。查看此处了解详情curl_getinfo。这可以提示您在哪里继续调查。
  • 嗨 @YvesLeBorg 我用 curl_getinfo 结果编辑我的问题,谢谢!!
  • 您的服务器请求看起来不像正在旅行。尝试查看 curl_error ,看看它对此有何评论。您的服务器上的 2016 端口出站是否打开?你能(从服务器)ping 175.139.27.203 吗?要做的这么多,时间却这么少。 :)
  • 嗨 @YvesLeBorg 尝试 curl_error 它返回“无法连接到主机”关于 ping 我将请求我的主机并更新你;)
  • 请发布您用于进行 curl 调用的完整代码。

标签: php web-services curl


【解决方案1】:

根据您的 curl_getinfo 输出,您的服务器端请求看起来不像正在旅行。另请查看 curl_error ,看看它对此有何评论。

您的服务器可能存在出站通信问题。您的服务器上的 2016 端口出站是否打开?你能(从服务器)ping 175.139.27.203 吗?

【讨论】:

  • 这是问题所在,我只知道ltcmobile.webhop.biz:2016 意味着我们的主机也应该需要打开端口 2016 ,我也学会了使用 curl_getinfo 和 curl_error 非常感谢!!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-05
  • 1970-01-01
  • 2020-05-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多