我需要使用curl向外部http API发出POST请求.当我使用curl命令行调用API时,它返回正确的数据.但是,当我从php脚本调用它时,我很难获得正确的数据.
当我从终端使用curl命令时,我得到了正确的数据:
curl -i -H"接受:application/json"-X POST -d"type_category_id = 4" http://example.com/api/
php中我的curl_setopts()中CURLOPT_POSTFIELDS的正确格式是什么?
我尝试了以下(并失败):
<?php
$data = "type_category_id=4";
$ch = curl_init('http://example.com/api/');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data))
);
$result = curl_exec($ch);
?>
Run Code Online (Sandbox Code Playgroud) 我需要将我的应用程序升级到Rails 3.2.16,当我这样做bundle update rails时会给我以下错误.
Bundler could not find compatible versions for gem "tilt":
In Gemfile:
sass-rails (= 3.2.6) ruby depends on
tilt (~> 1.3) ruby
slim (>= 0) ruby depends on
tilt (2.0.0)
Run Code Online (Sandbox Code Playgroud)
我的Gemfile:
gem 'sass-rails', '~> 3.2.6'
gem 'slim'
Run Code Online (Sandbox Code Playgroud)
我不知道如何解决这个问题.请帮忙.
谢谢,
我需要从控制器渲染一个json输出,我想在json中包含我的图像的缩略图版本.
如果我只使用:image_url它渲染json,则输出完整的图像URL,如果我使用:image它,它将列出所有可用的图像(包括缩略图).
如何在json中渲染图像的缩略图版本?
谢谢,