小编Sma*_*ndy的帖子

无法使用 Symfony HttpClient 检索错误消息

我使用 Symfony HttpClient 来调用外部 api。当 statusCode 为 200 时,我可以使用getContent()方法来检索 API 响应。如果 API 响应为 400,则抛出 ClientException 并且我无法获取外部 API 消息。

$httpClient = HttpClient::create();
$response = $httpClient->request($method, $url);
if (200 !== $response->getStatusCode()) {
    $apiResponse['statusCode'] = $response->getStatusCode();
    $httpInfo = $response->getInfo();
    $content = $response->getContent(); //this throws ClientException
}
Run Code Online (Sandbox Code Playgroud)

symfony symfony-http-client

6
推荐指数
1
解决办法
1482
查看次数

Silex 中的挂载操作 - 附加斜杠

我有一个在 Silex Framework 中开发的小型后端。我尝试使这个请求在 POST 上工作:

http://localhost/feedback/other

但是当使用挂载操作时,只有这个请求有效:

http://localhost/feedback/other/

如您所见,我必须在请求中添加一个额外的尾部斜杠。

以下是一些无法按预期工作的代码:

//index.php
$app->mount("/other", new FeedbackOther());

//FeedbackOther.php
$feedbackOther->get("/", "FeedbackOtherController::index")->bind('other');
$feedbackOther->post("","FeedbackOtherController::store");
Run Code Online (Sandbox Code Playgroud)

如果我做类似的事情

//index.php
$app->post('/other', "FeedbackOtherController::store");
$app->mount("/other", new FeedbackOther());

//FeedbackOther.php
$feedbackOther->get("/", "FeedbackOtherController::index")->bind('other');
Run Code Online (Sandbox Code Playgroud)

POST 请求无需附加斜杠即可工作,但在这种情况下,我看不到使用挂载操作的意义。

我也试过使用 .htacces 重写,但重写规则在 GET 中转换了 POST 请求。

php symfony silex

4
推荐指数
1
解决办法
1053
查看次数

标签 统计

symfony ×2

php ×1

silex ×1

symfony-http-client ×1