我正在尝试通过php执行此curl命令,但我无法使用GET请求发送urlencode数据
这是我的卷曲命令
curl -X GET \
-H "X-Parse-Application-Id: ..." \
-H "X-Parse-REST-API-Key: ..." \
-G \
--data-urlencode "where={\"createdAt\": \"2016-01-07T20:38:02.428Z\"}" \
https://api.parse.com/1/classes/Books';
这是我的PHP代码,直到
<?php
header('Content-Type: application/json');
$ParseAppID = "X-Parse-Application-Id: ... " ;
$ParseRestKey = "X-Parse-REST-API-Key: ... " ;
//$ParseMasterKey = ;
$GET ="GET";
$data = array("createdAt"=>"2016-01-09T08:42:36.675Z");
$data_string = json_encode($data);
$curl = curl_init();
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $GET);
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($curl, CURLOPT_HEADER, FALSE);
curl_setopt($curl, CURLOPT_HTTPHEADER, array($ParseAppID, $ParseRestKey));
curl_setopt($ch, CURLOPT_POSTFIELDS, urlencode('where='.$data_string));
curl_setopt($curl, CURLOPT_URL, "https://api.parse.com/1/classes/Text");
$result = curl_exec( $curl );
curl_close( $curl );
echo $result;
?>
答案 0 :(得分:1)
据我所知,对于获取请求,没有POSTFIELDS的等效项,因此您必须将其作为参数添加到网址上。
$("button").click(function() {
var giftDataArr = [];
$('tr').each(function() {
giftDataArr.push({
pointFrom: $(this).find('.st-points').val(),
pointTo: $(this).find('.ed-points').val(),
gift: $(this).find('.gift').val(),
type: $(this).find('input:radio:checked').val(),
comment: $(this).find('.comment').val()
});
})
console.log(giftDataArr);
});