这是我当前的代码:
$header = [
'phoneType' => $mobileType
];
\Drupal::logger("cam")->debug('PageNameHere retrieveAPINameHere REQUEST: '.json_encode($header));
$filterPhone = MAPClient2::req( 'get', $context, $header, NULL);
现在,我需要使用具有以下请求的新API进行两个请求:
{
"configuration": "techDescriptions",
"automated":"<phon>",
"lalaBox":true
}
{
"configuration": "techDescriptions",
"automationBu":"<phoneType>",
"lalaBox":false
}
这是正确的方法吗?
$header = [
"configuration": "techDescriptions",
"automationBu":"<phoneType>",
"lalaBox":false
];
$header = [
"configuration": "techDescriptions",
"automationBu":"<phoneType>",
"lalaBox":treu
];
\Drupal::logger("cam")->debug('PageNameHere retrieveNEWAPINameHere REQUEST: '.json_encode($header));
$filterPhone = MAPClient2::req( 'get', $context, $header, NULL);
答案 0 :(得分:0)
这样做时,您将覆盖$ header变量。您可能应该使用另一个名称,该名称对于您需要发送的第二个标头更有意义。我会放$ header2,以便您理解,但您应该找到一个更好的名称
$header = [
"configuration": "techDescriptions",
"automationBu":"<phoneType>",
"lalaBox":false
];
$header2 = [
"configuration": "techDescriptions",
"automationBu":"<phoneType>",
"lalaBox":treu
];
\Drupal::logger("cam")->debug('PageNameHere retrieveNEWAPINameHere REQUEST: '.json_encode($header));
$filterPhone = MAPClient2::req( 'get', $context, $header, NULL);
\Drupal::logger("cam")->debug('PageNameHere retrieveNEWAPINameHere REQUEST: '.json_encode($header));
$filterPhone = MAPClient2::req( 'get', $context, $header2, NULL);
答案 1 :(得分:0)
$header = [
"configuration": "techDescriptions",
"automationBu":"<phoneType>",
"lalaBox":false
];
\Drupal::logger("cam")->debug('PageNameHere retrieveNEWAPINameHere REQUEST: '.json_encode($header));
$filterPhone1 = MAPClient2::req( 'get', $context, $header, NULL);
$header = [
"configuration": "techDescriptions",
"automationBu":"<phoneType>",
"lalaBox":treu
];
\Drupal::logger("cam")->debug('PageNameHere retrieveNEWAPINameHere REQUEST: '.json_encode($header));
$filterPhone2 = MAPClient2::req( 'get', $context, $header, NULL);
只需执行2个请求。在您的示例中,您仅覆盖标头变量。而且我认为在第二个标头中,您的意思是真的不是treu吗?
答案 2 :(得分:0)
您还可以将2个标头放到一个数组中,然后再按两次调用它们:
\Drupal::logger("cam")->debug('PageNameHere retrieveNEWAPINameHere REQUEST: '.json_encode($header));
$filterPhone = MAPClient2::req( 'get', $context, $header[0], NULL);
\Drupal::logger("cam")->debug('PageNameHere retrieveNEWAPINameHere REQUEST: '.json_encode($header));
$filterPhone = MAPClient2::req( 'get', $context, $header[1], NULL);
但是您赢的并不多,但是以后想要添加更多标题时可能会更方便。