我已经建立了一个API。要对其执行搜索,我执行如下操作
$tableData = DB::table($table)->where('search', $search)->get();这将实质上形成一个类似于这样的URL (表和搜索被其他值所取代)。
https://something.com/api/returnSearch/{{table}}/{{search}}我的问题是这个。搜索项如下所示
某物(阿斯达/特易购)
所以完整的URL如下所示
https://something.com/api/returnSearch/someTable/something (asda/tesco)问题是搜索中的正斜杠,将阿斯达和特易购分开。当我在邮递员里测试它的时候
NotFoundHttpException在RouteCollection.php第161行中:
所以我猜想它认为正斜杠是url的一部分。有什么办法可以避免这种情况,同时仍然允许一个正斜杠搜索?
谢谢
发布于 2017-01-11 16:12:32
要在URL中包含具有特殊意义的字符,您需要根据URL格式规则转义/编码它们。具体来说:rawurlencode.
printf('https://something.com/api/returnSearch/%s/%s',
rawurlencode($table), rawurlencode($search))
// https://something.com/api/returnSearch/someTable/something%20%28asda%2Ftesco%29https://stackoverflow.com/questions/41595498
复制相似问题