英文:
http request from website to cloud function in php
问题
我想要从我的 PHP 网站触发一个 HTTP 云函数,以更新 Firestore 记录。
$url = 'https://us-central1-myprojectid.cloudfunctions.net/updateOrderStatus';
$client = new Client();
$response = $client->post($url, [
'form_params' => [
'orderId' => '2',
'newStatus' => 3,
]
]);
这是我的云函数:
exports.updateOrderStatus = functions.https.onCall(async (data, context) => {
console.log("Inside updateOrderStatus function's onCall");
console.log(data);
});
但是我在云函数中收到以下错误:
请求的 Content-Type 不正确。应为 application/x-www-form-urlencoded
并且在我的 Laravel 屏幕中收到以下异常:
客户端错误:`POST https://us-central1-myprojectid.cloudfunctions.net/updateOrderStatus` 导致 `400 Bad Request` 响应:{"error":{"message":"Bad Request","status":"INVALID_ARGUMENT"}}
英文:
I want to trigger a HTTP cloud function from my php website to update a firestore record.
$url = 'https://us-central1-myprojectid.cloudfunctions.net/updateOrderStatus';
$client = new Client();
$response = $client->post($url, [
'form_params' => [
'orderId' => '2',
'newStatus' => 3,
]
]);
Here is my cloud function
exports.updateOrderStatus = functions.https.onCall(async (data, context) => {
console.log("Inside updateOrderStatus function's onCall");
console.log(data);
}
);
But I am getting below error in cloud function
Request has incorrect Content-Type. application/x-www-form-urlencoded
and below exception in my laravel screen
Client error: `POST https://us-central1-myprojectid.cloudfunctions.net/updateOrderStatus` resulted in a `400 Bad Request` response: {"error":{"message":"Bad Request","status":"INVALID_ARGUMENT"}}
答案1
得分: 0
如果您使用的是Laravel 7+,请使用Http
外观...
所以,您的代码应该是:
use Illuminate\Support\Facades\Http;
Http::post(
'https://us-central1-myprojectid.cloudfunctions.net/updateOrderStatus',
[
'form_params' => [
'orderId' => '2',
'newStatus' => 3,
]
]
);
英文:
If you are using Laravel 7+, use the Http
facade...
So, your code should be:
use Illuminate\Support\Facades\Http;
Http::post(
'https://us-central1-myprojectid.cloudfunctions.net/updateOrderStatus',
[
'form_params' => [
'orderId' => '2',
'newStatus' => 3,
]
]
);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论