通过 php 客户端的 HTTP 放置
HTTP Put via php client
我正在为一个名为 Xena.biz
的会计网站写一个小 'app'
系统有一个使用 oAuth2 连接的 API。我整理的一切——我可以完美地检索我需要的信息。现在我需要将 PUT 字符串提交回 Xena - 这是我无法弄清楚的地方。
系统建立在一个名为 XenaClient.php 的文件上,该文件包含所有授权调用和所有请求。
这是我如何检索信息的示例:
<?
require('XenaClient.php');
const CLIENT_ID = 'SECRET';
const CLIENT_SECRET = 'VERY SECRET';
$xenaclient = new XenaOAuth2Client(CLIENT_ID, CLIENT_SECRET);
$xenaclient->setAccessToken($_COOKIE["MaskedCookieName"]);
$ordertask = $xenaclient->fetch('https://my.xena.biz/Api/Fiscal/'.$_GET["fiscal"].'/OrderTask/'.$_GET["orderId"]);
var_dump($ordertask);
?>
但现在我想通过 PUT 发送信息。根据 XenaClient.php 脚本,我应该使用命令 $xenaclient->fetch($url,$parameters);
所以这是我的镜头
require('XenaClient.php');
const CLIENT_ID = 'SECRET';
const CLIENT_SECRET = 'VERY SECRET';
$xenaclient = new XenaOAuth2Client(CLIENT_ID, CLIENT_SECRET);
$xenaclient->setAccessToken($_COOKIE["MaskedCookieName"]);
$xenaclient->fetch('https://my.xena.biz/Api/Fiscal/96946/Order/243936250/Confirmation',array('ConfirmationDate'=>NULL,'ConfirmationReportLayoutId'=>261205291));
?>
这不会扭转任何局面,也不会在会计系统内产生预期的效果。从 Xena 自己那里得不到帮助,所以这就是为什么我问你们,希望你们能帮助我。
这里有几点建议:
API 资源:https://dev.xena.biz
XenaClient.php: https://github.com/EG-BRS/Xena.ExampleApp.PHP/blob/master/XenaClient.php
XenoOAuth2Client::fetch tells you, that the third parameter to the fetch function - although optional - determines the method of the request. Default ist GET (XenaOAuth2Client::HTTP_METHOD_GET
), so if you want PUT, you should explicitly provide the appropriate PUT parameter (other methods see the XenoOAuth2Client class constants:
$xenaclient->fetch(
'https://my.xena.biz/Api/Fiscal/96946/Order/243936250/Confirmation',
array('ConfirmationReportLayoutId'=>261205291),
XenaOAuth2Client::HTTP_METHOD_PUT
);
大多数 API 今天消耗 json,也许 它应该是 json...
$xenaclient->fetch(
'https://my.xena.biz/Api/Fiscal/96946/Order/243936250/Confirmation',
json_encode(array('ConfirmationReportLayoutId'=>261205291)),
XenaOAuth2Client::HTTP_METHOD_PUT
);
我正在为一个名为 Xena.biz
的会计网站写一个小 'app'系统有一个使用 oAuth2 连接的 API。我整理的一切——我可以完美地检索我需要的信息。现在我需要将 PUT 字符串提交回 Xena - 这是我无法弄清楚的地方。
系统建立在一个名为 XenaClient.php 的文件上,该文件包含所有授权调用和所有请求。
这是我如何检索信息的示例:
<?
require('XenaClient.php');
const CLIENT_ID = 'SECRET';
const CLIENT_SECRET = 'VERY SECRET';
$xenaclient = new XenaOAuth2Client(CLIENT_ID, CLIENT_SECRET);
$xenaclient->setAccessToken($_COOKIE["MaskedCookieName"]);
$ordertask = $xenaclient->fetch('https://my.xena.biz/Api/Fiscal/'.$_GET["fiscal"].'/OrderTask/'.$_GET["orderId"]);
var_dump($ordertask);
?>
但现在我想通过 PUT 发送信息。根据 XenaClient.php 脚本,我应该使用命令 $xenaclient->fetch($url,$parameters);
所以这是我的镜头
require('XenaClient.php');
const CLIENT_ID = 'SECRET';
const CLIENT_SECRET = 'VERY SECRET';
$xenaclient = new XenaOAuth2Client(CLIENT_ID, CLIENT_SECRET);
$xenaclient->setAccessToken($_COOKIE["MaskedCookieName"]);
$xenaclient->fetch('https://my.xena.biz/Api/Fiscal/96946/Order/243936250/Confirmation',array('ConfirmationDate'=>NULL,'ConfirmationReportLayoutId'=>261205291));
?>
这不会扭转任何局面,也不会在会计系统内产生预期的效果。从 Xena 自己那里得不到帮助,所以这就是为什么我问你们,希望你们能帮助我。
这里有几点建议:
API 资源:https://dev.xena.biz
XenaClient.php: https://github.com/EG-BRS/Xena.ExampleApp.PHP/blob/master/XenaClient.php
XenoOAuth2Client::fetch tells you, that the third parameter to the fetch function - although optional - determines the method of the request. Default ist GET (XenaOAuth2Client::HTTP_METHOD_GET
), so if you want PUT, you should explicitly provide the appropriate PUT parameter (other methods see the XenoOAuth2Client class constants:
$xenaclient->fetch(
'https://my.xena.biz/Api/Fiscal/96946/Order/243936250/Confirmation',
array('ConfirmationReportLayoutId'=>261205291),
XenaOAuth2Client::HTTP_METHOD_PUT
);
大多数 API 今天消耗 json,也许 它应该是 json...
$xenaclient->fetch(
'https://my.xena.biz/Api/Fiscal/96946/Order/243936250/Confirmation',
json_encode(array('ConfirmationReportLayoutId'=>261205291)),
XenaOAuth2Client::HTTP_METHOD_PUT
);