如何将参数传递给 api post 方法?
How to pass parameter to an api post method?
我正在使用 guzzle 调用我的 api,并且在我的 url 中包含一个动态 ID
http://myapiurl.com/products/{productId}/phone
$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 传递给 url。
it generate only http://myapiurl.com (baseurl only)
那是因为您将“/”传递给了 post()
方法。尝试:
$client = new Client([
'base_url' => [
'http://myapiurl.com'
]
]);
$repsonse = $client->post(
'/product/' + $productId + '/phone',
[
'json' => [
'title' => $title,
'description' => $description,
],
]
);
我正在使用 guzzle 调用我的 api,并且在我的 url 中包含一个动态 ID http://myapiurl.com/products/{productId}/phone
$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 传递给 url。
it generate only http://myapiurl.com (baseurl only)
那是因为您将“/”传递给了 post()
方法。尝试:
$client = new Client([
'base_url' => [
'http://myapiurl.com'
]
]);
$repsonse = $client->post(
'/product/' + $productId + '/phone',
[
'json' => [
'title' => $title,
'description' => $description,
],
]
);