【发布时间】:2015-05-03 03:19:37
【问题描述】:
我正在使用 Guzzle 3 来处理超媒体 HTTP API,并且在使用 URL 路径作为参数时遇到了一些问题。该服务将返回 URL 路径以访问资源,并且除了参数化的路径正在被 URLEncoded 之外,大部分都在工作。
这是服务描述中的操作示例
"getWidget": {
"uri": "{path}",
"summary": "Get Widget",
"httpMethod": "GET",
"responseType": "class",
"responseClass": "Service\\Responses\\Widget",
"parameters": {
"path": {
"location": "uri"
}
}
}
我正在执行操作:
$client = WidgetClient::factory(array('base_url' => 'example.com'));
$args = array('path' => '/widget/abc123');
$command = $client->getCommand('getWidget', $args);
$result = $command->execute();
执行客户端请求时:http://example.com/%2Fwidget%2Fabc123 而不是http://example.com/widgetabc123
我已将参数处理追溯到UriTemplate::expandMatch(),它执行对参数进行编码的rawurlencode($variable) 调用——但我看不到避免编码的明确方法。
那么,使用 Guzzle 3 及其服务描述,如何在不进行 URLEncoded 的情况下将 URL 路径作为参数传递?
【问题讨论】: