在php中使用curl -G标志 [英] using curl -G flag in php

查看:142
本文介绍了在php中使用curl -G标志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的curl命令:

Here is my curl command:

curl -X GET \
  -H "X-Parse-Application-Id: ..." \
  -H "X-Parse-REST-API-Key: ..." \
  -G \
  --data-urlencode 'where={"playerName":"Jonathan Walsh"}' \
  --data-urlencode 'count=1' \
  --data-urlencode 'limit=0' \
  https://api.parse.com/1/classes/GameScore

我使用php 。

对于-X,-HI知道等效:

For the -X, -H I know the equivalent:

curl_setopt($ch, CURLOPT_URL, "https://api.parse.com/1/classes/GameScore");

  curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'X-Parse-Application-Id: ...',
    'X-Parse-REST-API-Key: ...',
    ));

关于-G,--data标志?

What about the -G, --data flags?

等效代码是什么?

推荐答案

发布数据>

For posting the data(you can use array though):

$request = 'where={"playerName":"Jonathan Walsh"}&count=1&limit=0';
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$request);

在您的网址中的 https://

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

从curl执行日期返回

To return the date from curl execution

curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);

最后:

$result = curl_exec($ch);

UPDATE:

未检查您是否正在执行 GET 操作。如果你 GET ,那么它只是

Didn't check that you are doing GET operation. If you do GET, then it will be simply

$request = 'where={"playerName":"Jonathan Walsh"}&count=1&limit=0';
$url = "http://example.com/" . "?" . $request;
curl_setopt($ch, CURLOPT_URL,$url);

这篇关于在php中使用curl -G标志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆