English 中文(简体)
使用 CURL 读取 JSON 数据
原标题:Reading JSON data with CURL
  • 时间:2012-05-24 12:17:55
  •  标签:
  • php
  • curl

我试图用 CURL 读取 URL 的 URL 。 当我在浏览器中运行这个 URL 时, 一个文件会下载在我的系统中, 文件的内容会如下

现在我要拿到这个文件的内容。 到目前为止,我用了这个...

$send_curl = curl_init($url);
curl_setopt($send_curl, CURLOPT_URL, $url);
curl_setopt($send_curl, CURLOPT_HEADER, false);
curl_setopt($send_curl, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($send_curl, CURLOPT_POST, TRUE);
curl_setopt($send_curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($send_curl, CURLOPT_HTTPHEADER,array( Accept: application/json , "Content-type: application/json"));
curl_setopt($send_curl, CURLOPT_FAILONERROR, FALSE);
curl_setopt($send_curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($send_curl, CURLOPT_SSL_VERIFYHOST, FALSE);
$json_response = curl_exec($send_curl);
$status = curl_getinfo($send_curl, CURLINFO_HTTP_CODE);
curl_close($send_curl);

$response = json_decode($json_response, true);

但我没有得到正确的回应 知道我哪里出错了吗?

最佳回答

在对本地json url进行快速测试后, 我发现如果你移除这个, 你会没事的:

curl_seetopt($send_curl, CURLOPT_POST, TRUE); ($send_curl, CURLOPT_POST, TRUE);

我的意思是,如果你没有尝试实际的POST。 否则,它总是给我一个"400错误请求"错误。

希望这有帮助!

问题回答

暂无回答




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签