我使用guzzle来调用我的api,并且在我的url中包含一个动态id http://myapiurl.com/products/ {的productId} /电话
$client = new Client([
'base_url' => [
'http://myapiurl.com/product/{productId}/phone',
['productId' => $productId]
]
]);
$repsonse = $client->post(
'/',
[
json' => [
'title' => $title,
'description' => $description,
],
]
);
但它只生成http://myapiurl.com(仅限baseurl) 我无法将我的productId传递给网址。
答案 0 :(得分:1)
它仅生成http://myapiurl.com(仅限baseurl)
那是因为你通过了' /'到post()
方法。试试:
$client = new Client([
'base_url' => [
'http://myapiurl.com'
]
]);
$repsonse = $client->post(
'/product/' + $productId + '/phone',
[
'json' => [
'title' => $title,
'description' => $description,
],
]
);