PHP file_get_contents()จะคืนค่ากลับมาเป็น bool(เท็จ)เมื่อคนเดียวกับข้อความจะได้ผลในเบราว์เซอร์

0

คำถาม

บางอย่างรหัสที่ถูกทำงานสำหรับเดือนทันใดนั้นไม่ได้ทำงานอยู่ ฉันต้องทำให้มันแคบลง PHP file_get_contents ส่วน. นี่คือตัดดอกตูมของรหัส:

// This upper portion was added to send a user-agent with the request
$opts = [
    "http" => [
        "method" => "GET",
        "header" => "Accept-language: en\r\n" .
        "User-Agent: Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.102011-10-16 20:23:10\r\n",
    ],
];
$context = stream_context_create($opts);
// End of the added part except for the actual get-file-contents request line


$ViewLat = 40.7;
$ViewLng = -73.9;
$Distance = 1000;
$input1 = "https://api.helium.io/v1/hotspots/location/distance?lat=40.7&lon=-73.9&distance=1000";
$input2 = "https://api.helium.io/v1/hotspots/location/distance/?lat=$ViewLat&lon=$ViewLng&distance=$Distance";
$json_string = file_get_contents(urlencode($input2), false, $context); // added the last 2 arguments

var_dump($ViewLat);
echo "<br>";
var_dump($ViewLng);
echo "<br>";
var_dump($Distance);
echo "<br>";
var_dump($input1);
echo "<br>";
var_dump($json_string);

มันไม่สำคัญอะไรถ้าหากฉันใช้$input1 หรือ$input2 พวกเขาทั้งคู่กลับมา bool(เท็จ)ใน var_dump ouput. แต่ถ้าคุณวางข้อความโดยตรงเข้าไปในเบราว์เซอร์มันกลับมาเป็นอาเรย์ของข้อมูลออกมา

ดรหัสนี้กำลังทำงานกลับมาอยู่ในเดือนสิงหาคม/กันยายนแต่ตอนนี้ไม่ได้.

นี่คือ var_dump ouput:

float(40.7)
float(-73.9)
int(1000)
string(84) "https://api.helium.io/v1/hotspots/location/distance?lat=40.7&lon=-73.9&distance=1000"
bool(false)
api file-get-contents php
2021-11-23 19:13:04
1

คำตอบที่ดีที่สุด

0

ความสำเร็จ!!!! ฉันต้องเพิ่มบางของผู้ใช้-เจ้าหน้าที่ข้อมูลไปยังแฟ้ม-ได้-เนื้อหาของอยากขอให้ช่วยอะไรหน่อย ฉันจะปรับปรุงรหัสอยู่เหนือเพื่อเพิ่มอะไรทำงาน

2021-11-23 20:48:16

ในภาษาอื่นๆ

หน้านี้อยู่ในภาษาอื่นๆ

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................

ดังอยู่ในนี้หมวดหมู่

ดังคำถามอยู่ในนี้หมวดหมู่