我正在尝试开发一个php客户端来与hbase restapi交互。但是我找不到使用json请求创建scanner的方法。我能找到的所有例子都使用xml格式。只是想知道是否可以使用json格式发送。
下面的代码返回了错误消息:“http/1.1 500不能反序列化java.lang.string示例的起始\u数组令牌”
<?php
$headers = array(
'Accept: application/json',
'Content-Type: application/json',
);
if (!file_exists(__DIR__ . '/tmp')) {
mkdir(__DIR__ . '/tmp', 0777);
}
$scannerFile = __DIR__ . '/tmp/scanner';
if (!file_exists($scannerFile)) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://hbase_uri:20550/news/scanner");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_GSSNEGOTIATE);
curl_setopt($ch, CURLOPT_USERPWD, ":");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(array(
'batch' => 10,
'filter' => array(
array(
'type' => 'PrefixFilter',
'value' => 'u123',
),
),
)));
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$page = curl_exec($ch);
file_put_contents($scannerFile, $page);
curl_close($ch);
} else {
$s = file_get_contents($scannerFile);
$parts = explode('Location: http://hbase_uri:20550/news/scanner/', $s);
$parts = explode("\n", $parts[1]);
$parts[0] = trim($parts[0]);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://hbase_uri:20550/news/scanner/" . $parts[0]);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_GSSNEGOTIATE);
curl_setopt($ch, CURLOPT_USERPWD, ":");
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$page = curl_exec($ch);
file_put_contents(__DIR__ . '/tmp/result', $page);
curl_close($ch);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://hbase_uri:20550/news/scanner/" . $parts[0]);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_GSSNEGOTIATE);
curl_setopt($ch, CURLOPT_USERPWD, ":");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$page = curl_exec($ch);
file_put_contents(__DIR__ . '/tmp/result_delete', $page);
curl_close($ch);
}
2条答案
按热度按时间elcex8rz1#
为了未来的游客。
使用@kiang answer,我成功地制作了一个创建扫描仪的 curl 贴子:
他回来了
什么可能有用:
使用这些例子(你需要
"
(标志)查找scannermodel的文档。
pexxcrt22#
我从别人的暗示中得到了答案: