查询字符串中的通配符 C#

发布于 12-17 11:05 字数 294 浏览 3 评论 0原文

不知道如何问这个问题或者是否可以做到。

我有一个 ID 号,我想测试它是否与存储在我正在使用的 API 中的 URL 查询字符串中的 ID 匹配。

因此,如果我要搜索的 URL 包含 http://www.testurl.com/page?key=55555,我只想在该 url“包含”该数字时放入我的 http 请求。测试 url 是否完全相等已被证明是有问题的,因为存储的查询字符串还有很多其他信息。

考虑到我已经对 html 进行了编码,查询字符串中的通配符是否可能?任何帮助表示赞赏。谢谢你!

Not sure how to ask this or if it can be done.

I have an ID number, that I want to test if it matches an ID in a URL query string that is stored in an API I am working with.

So if the URL i want to search contains a http://www.testurl.com/page?key=55555, I just want to put in my http request if that url 'contains' that number. Testing if the url is exactly equal has proved problematic as there is a lot of other info the stored query string.

Are wildcards within query strings even possible, considering I am encoding the html already? Any help is appreciated. Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

愚人国度2024-12-24 11:05:42
string[] myUrls = new string[] {
  "http://www.testurl.com/page?key=55555",
  "http://www.testurl.com/page?key=555556789",
  "http://www.testurl.com/page?foo=bar&key=55555&baz=938355555"};

string myToken = "key=55555";
bool exists;

foreach(string url in myUrls)
{
    System.Uri uri = new System.Uri(url);
    string q = uri.GetComponents(UriComponents.Query, UriFormat.Unescaped);

    if (q.Split('&').Any(x=>x== myToken))
    {
       Console.WriteLine(string.Format("found it in '{0}'", url));
    }
}
string[] myUrls = new string[] {
  "http://www.testurl.com/page?key=55555",
  "http://www.testurl.com/page?key=555556789",
  "http://www.testurl.com/page?foo=bar&key=55555&baz=938355555"};

string myToken = "key=55555";
bool exists;

foreach(string url in myUrls)
{
    System.Uri uri = new System.Uri(url);
    string q = uri.GetComponents(UriComponents.Query, UriFormat.Unescaped);

    if (q.Split('&').Any(x=>x== myToken))
    {
       Console.WriteLine(string.Format("found it in '{0}'", url));
    }
}
私藏温柔2024-12-24 11:05:42

如果您可以访问 QueryString,您可以这样做:

if (HttpContext.Current.Request.QueryString["key"].ToLower() == "5555")
    //do something

If you can access the QueryString, you could just do this:

if (HttpContext.Current.Request.QueryString["key"].ToLower() == "5555")
    //do something
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文