Native encodeURIComponent不支持编码感叹号 - !我需要在url的查询参数中正确编码感叹号.
node.js querystring.stringify()也不是..
是使用自定义函数的唯一方法 - https://github.com/kvz/phpjs/blob/master/functions/url/urlencode.js#L30?
我需要在 REST API 中支持 OR 语句,但我不知道如何构建正确的查询字符串。也许,像这样的事情?
或者可能存在标准解决方案?
搜索了这么久但没有得到任何可行的答案.
A)输入:
$array = array(
'order_source' => array('google','facebook'),
'order_medium' => 'google-text'
);
Run Code Online (Sandbox Code Playgroud)
看起来像:
Array
(
[order_source] => Array
(
[0] => google
[1] => facebook
)
[order_medium] => google-text
)
Run Code Online (Sandbox Code Playgroud)
B)所需产量:
order_source =谷歌&order_source = Facebook和order_medium =谷歌的文本
C)我尝试过的(http://3v4l.org/b3OYo):
$arr = array('order_source' => array('google','facebook'), 'order_medium' => 'google-text');
function bqs($array, $qs='')
{
foreach($array as $par => $val)
{
if(is_array($val))
{
bqs($val, $qs);
}
else
{
$qs .= $par.'='.$val.'&';
}
}
return $qs;
}
echo $qss = bqs($arr);
Run Code Online (Sandbox Code Playgroud)
D)我得到了什么: …
我需要在我们的数据库中存储用户搜索查询以跟踪搜索历史记录.我知道request.original_url会将查询字符串作为绝对URL.
http://www.example.com/search?utf8=%E2%9C%93&keywords=cars&view=grid
Run Code Online (Sandbox Code Playgroud)
我宁愿存储相对url路径.话虽如此,对于所有params的相对url,request.original_fullpath和request.fullpath之间有什么区别?他们似乎是一回事?
request.original_fullpath
/search?utf8=%E2%9C%93&keywords=cars&view=grid
Run Code Online (Sandbox Code Playgroud)
request.fullpath
/search?utf8=%E2%9C%93&keywords=cars&view=grid
Run Code Online (Sandbox Code Playgroud) TL; TR:在查询的URL部分是(第一个)问号还是只是一个后跟查询的分隔符?
在RFC 1738,部分3.3,表明"?" (问号)不是查询字符串的一部分,只是将其与路径分开:
http://<host>:<port>/<path>?<searchpart>
Run Code Online (Sandbox Code Playgroud)
RFC 3986附录A中提出的语法也表示"?" 不是实际查询字符串的一部分:
URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
Run Code Online (Sandbox Code Playgroud)
现在,让我们考虑两个网址:
http://server.com/api/item.jsonhttp://server.com/api/item.json?它们是等同的还是不同的?
区分它们并用于识别两种不同的资源是否有效?
在 Google Oauth2 实现中,我尝试使用 guzzle 调用交换令牌的授权代码。
以下 guzzle 调用工作正常并返回预期值:
$result = $this->client->post(
'https://www.googleapis.com/oauth2/v3/token?code=<authorization_code>&redirect_uri=<redirect_uri>&client_id=<client_id>&client_secret=<client_secret>&grant_type=authorization_code')
->getBody()->getContents();
Run Code Online (Sandbox Code Playgroud)
然而,这似乎是一种挂载 post 请求的肮脏方式。
我尝试了以下方法以使其更清洁:
$result = $this->client->post(
'https://www.googleapis.com/oauth2/v3/token',
[
'query' =>
[
'code' => <authorization_code>,
'redirect_uri' => <redirect_uri>,
'client_id' => <client_id>,
'client_secret' => <client_secret>
'grant_type' => 'authorization_code',
]
]
)->getBody()->getContents();
Run Code Online (Sandbox Code Playgroud)
但是,第二次调用会生成Malformed Json错误消息。
知道我可能做错了什么,或者如何调试上面示例中生成的最终 url?
在我的node.js应用程序中,我正在使用一个接受调用的API,如下所示
\n\nhttp://myapi.com/action?url= https://www.test.com/play?action=jump\nRun Code Online (Sandbox Code Playgroud)\n\n然后根据传入 URL 参数的参数(例如 \xe2\x80\x93 \xe2\x80\x98action=jump\xe2\x80\x99),API 返回特定响应。
\n\n我遇到的问题是,在某些情况下,发送到 API 的 URL 可能已经带有带有查询字符串的问号(?song=portrait)
\n\nhttp://myapi.com/action?url= https://www.test.com/play?song=portrait?action=jump\nRun Code Online (Sandbox Code Playgroud)\n\n在这种情况下,API 会发回不正确的响应,因为它\xe2\x80\x99s 使用查询字符串中的第一个问号参数。例子?song=portrait
在不修改 API 的情况下,如何确保 API 读取末尾的参数 - 例如 \xe2\x80\x93action=jump
有没有办法避开第一个问号,同时保留有效的 URL 或者我如何使用url.format()或url.parse()解决这个问题
我忘记补充一点,我已经对传递到 URL 参数中的 URL 进行了编码。
\n如何读取aspx页面中的任何字符串.
例如:http://foo.com/bike stand
我想在指定的aspx页面中读取/获取字符串.预期页面字符串是自行车站
预期页面是getstring.aspx
在这里,我想读取字符串并重定向到指定的页面.
注意:我喜欢在ASP.Net(不使用MVC)中执行此操作
我有一个 .NET Core 6.0 Azure Function HTTP 触发器。
我希望以这两种常见形式处理数组查询字符串参数:
?param=foo¶m=escape%2Ctest?param=foo,escape%2Ctest在这两种情况下我都想提取数组["foo", "escape,test"]。
我惊讶地发现我可用的查询字符串解析选项要么不支持逗号语法,要么不支持将查询字符串作为参数分组的一部分进行 URL 解码。
我尝试过使用几种不同的 dotnet API:
System.Web.HttpUtility.ParseQueryStringMicrosoft.AspNetCore.WebUtilities.QueryHelpers.ParseQueryMicrosoft.AspNetCore.Http.HttpRequest.Queryvar qs = "?param=foo,escape%2Ctest";
var a = httpRequest.Query["param"];
// ["foo,escape,test"]
var b = HttpUtility.ParseQueryString(qs)["param"];
// "foo,escape,test"
var c = QueryHelpers.ParseQuery(qs)["param"];
// ["foo,escape,test"]
Run Code Online (Sandbox Code Playgroud)
我有点惊讶的是不支持逗号分隔格式。我感到非常惊讶的是,似乎没有一种方法可以在不解码查询字符串参数的情况下获取分段查询字符串(这会阻止区分 和param=foo,escape%2Ctest)?param=foo,escape,test。
我将在下面将我当前的解决方案作为“答案”发布,但我希望我缺少一个使用 .NET 库的更简单的解决方案。如果有人能指出我在这里错过了什么,我将不胜感激。
我正在使用最新版本的 Next.js (13.4) 和新的应用程序路由器。
在我的应用程序中,我有一个 Link 组件,其按钮位于 ../components/products.tsx 文件中。
每个产品都有一个“详细信息”按钮,可使用“链接”组件导航到动态路线。我使用链接组件的路径名和查询属性来传递查询参数和路由。
以下是 ../components/products.tsx 文件中 Link 组件的示例:
<Link href={{
pathname:`product/${item._id}`,
query:{
_id: item._id,
title: item.title,
description: item.description,
oldPrice: item.oldPrice,
price: item.price,
brand: item.brand,
image: item.image,
isNew: item.isNew,
category: item.category,
},
}}
as ={`product/${item._id}`}
>
Run Code Online (Sandbox Code Playgroud)
在路径为 app/product/[id] 的动态路由组件 (page.tsx) 中,我想访问查询参数并将它们呈现在页面上。以下是 page.tsx 文件的示例:
import React from 'react';
import { useRouter } from 'next/router';
const ProductPage = () => {
const router = useRouter();
const query = router.query;
return (
<div>
<h1>Product Details</h1>
<p>ID: {query._id}</p> …Run Code Online (Sandbox Code Playgroud) query-string next.js next-router nextjs-dynamic-routing next.js13