curl 在我的共享主機上無法正常工作 (curl not working in the right way on my shared hosting)


問題描述

curl 在我的共享主機上無法正常工作 (curl not working in the right way on my shared hosting)

我的問題是 curl 在我的主機上不能以正確的方式工作,但在我的本地主機上卻能正常工作。

這是我用來測試的代碼:

$url = 'https://www.instagram.com/nasa/?__a=1';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("User‑Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en‑US; rv:1.8.1.15) Gecko/20080623 Firefox/2.0.0.15") ); 
curl_setopt($ch, CURLOPT_NOBODY, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result= curl_exec ($ch);
curl_close ($ch);
echo style_print_r( $result );

在我的本地主機中,代碼的結果是這樣的:enter image description here

但在我的託管結果是這樣的:在此處輸入圖片描述

在我的託管中,它似乎試圖加載整個頁面:(

如何解決這個問題?

編輯:這是在我的主機中打印的源代碼:在此處輸入圖片描述


參考解法

方法 1:

Please check the Curl in your shared hosting

If you want to check whether the hosting service you are using has activated CURL or not, please create a php file with the following contents:

<?php
   // Script to test if the CURL extension is installed on this server

   // Define function to test
   function _is_curl_installed() {
       if  (in_array  ('curl', get_loaded_extensions())) {
   Â Â Â Â Â Â Â  return true;
   Â Â Â  }
   Â Â Â  else {
   Â Â Â Â Â Â Â  return false;
   Â Â Â  }
   }

   // Ouput text to user based on test
   if (_is_curl_installed()) {
      Â  echo "cURL is <span style=\"color:blue\">installed</span> on this server";
   } else {
      Â  echo "cURL is NOT <span style=\"color:red\">installed</span> on this server";
   }
?>

You can save the file with any file name, for example curl.php, after you save it, please access it via your web browser, for example at the address www.yourdomain.com/curl.php to find out the results.

(by JohnFarhan Yudhi Fatah)

參考文件

  1. curl not working in the right way on my shared hosting (CC BY‑SA 2.5/3.0/4.0)

#curl #file-get-contents #PHP #HTTPS #shared-hosting






相關問題

如何在所有 PayPal 交易中退還費用 (How to return fee in all PayPal transactions)

Cú pháp lệnh curl để đăng ký device_token trên Urban Airship là gì? (What is curl command syntax for device_token registration on Urban Airship?)

Nhận thời lượng video trên youtube từ URL với bash (Get youtube video duration from URL with bash)

đăng dữ liệu json với php curl cho đa phần / dữ liệu biểu mẫu để tải lên tệp nếu cakephp 2 (post json data with php curl for multipart/form-data for file upload vía cakephp 2)

ApacheMonitor 上的捲曲錯誤 (Curl error on ApacheMonitor)

從 ASP.net 使用 PHP 中的 POST 數據抓取數據 (Scraping data with POST data in PHP from ASP.net)

收聽推送消息? (Listen to a push message?)

在 PHP 中使用 cURL 的 RAW POST (RAW POST using cURL in PHP)

使用 php 和 curl 更新 mediawiki (using php and curl to update mediawiki)

在 Makefile 中鏈接 cURL (Linking cURL in Makefile)

將我的 .php 輸出發送到 curl 命令,該命令使用機器人在電報上向我發送消息 (Send my .php output to a curl command that messages me on telegram using a bot)

使用 Google My Business API 和 PHP 更新/修補本地帖子 (Updating/Patching a Local Post with Google My Business API and PHP)







留言討論