[英]How to do a get request twice in PHP?
Here's my current code: 这是我当前的代码:
$header = [
'phoneType' => $mobileType
];
\Drupal::logger("cam")->debug('PageNameHere retrieveAPINameHere REQUEST: '.json_encode($header));
$filterPhone = MAPClient2::req( 'get', $context, $header, NULL);
Now, I need to make two request now with a new API with the following request: 现在,我需要使用以下请求通过新API发出两个请求:
{
"configuration": "techDescriptions",
"automated":"<phon>",
"lalaBox":true
}
{
"configuration": "techDescriptions",
"automationBu":"<phoneType>",
"lalaBox":false
}
Is this the right way to do it? 这是正确的方法吗?
$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);
When doing this you overwrite the $header variable. 执行此操作时,您将覆盖$ header变量。 You should maybe have another name that makes more sense for the second header you need to send.
您可能应该使用另一个名称,该名称对于您需要发送的第二个标头更有意义。 I'll put $header2 so you understand but you should find a better name
我会放$ 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);
$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);
Just do 2 requests. 只需执行2个请求。 In your example, you only overwrite the header variable.
在您的示例中,您仅覆盖标头变量。 And I think the in the second header you mean true not treu?
我认为在第二个标头中,您的意思是真的吗?
You could also put the 2 headers together in one array and later call them twice as : 您也可以将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);
But you don't win much though, but might be more convenient later when you want to add more headers. 但是您不会赢很多,但是以后想要添加更多标题时可能会更方便。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.