【发布时间】:2016-12-30 20:06:14
【问题描述】:
我是 Slim Framework 3 的新手。我在访问具有 Api Key 标头值的 Web 服务时遇到问题。我有一个 Api Key 值并想访问 Web 服务以获取 JSON 数据。这是我的瘦 get 方法代码:
$app->get('/getbooking/{id}', function (Request $request, Response $response, $args) {
$id = $args['id'];
$string = file_get_contents('http://maindomain.com/webapi/user/'.$id);
//Still confuse how to set header value to access the web service with Api Key in the header included.
});
我已经尝试在 Postman(chrome 应用程序)中访问 Web 服务,我得到了结果。我使用 GET 方法并为 Api Key 设置 Headers 值。
但是如何在 Slim 3 中设置 Headers 值以访问 Web 服务?
感谢您的提前:)
【问题讨论】:
-
我认为 Alin Purcaru 在这里的回答会对你有所帮助stackoverflow.com/questions/35439409/…
-
你想访问
'http://maindomain.com/webapi/user/'.$idurl 在请求中设置自定义标头吗?