处理带变量名的URL,用C#是否能行?

wanghi 2012-04-04 07:24:38
有个页面,上面有很多链接
带了变量名的那种,比如
'http://'+sURL+'defaulthmr.asp?popmembers=' + pID + '&isb=0&lng=' + sLNG
变量很多都是在js 文件里面定义的

我需要找到对应的,需要的url 并且发送get

这种链接用C#处理是否方便?大概的做法是如何?

我对C# 不是太熟悉,不知道我的描述是否已经清晰

先谢谢大家
...全文
108 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
蔡袅 2012-04-04
  • 打赏
  • 举报
回复
UriTemplate 类

UriTemplate template = new UriTemplate("weather/{state}/{city}?forecast={day}");
Uri prefix = new Uri("http://localhost");

Console.WriteLine("PathSegmentVariableNames:");
foreach (string name in template.PathSegmentVariableNames)
{
Console.WriteLine(" {0}", name);
}
Console.WriteLine();

Console.WriteLine("QueryValueVariableNames:");
foreach (string name in template.QueryValueVariableNames)
{
Console.WriteLine(" {0}", name);
}
Console.WriteLine();

Uri positionalUri = template.BindByPosition(prefix, "Washington", "Redmond", "Today");

NameValueCollection parameters = new NameValueCollection();
parameters.Add("state", "Washington");
parameters.Add("city", "Redmond");
parameters.Add("day", "Today");
Uri namedUri = template.BindByName(prefix, parameters);

Uri fullUri = new Uri("http://localhost/weather/Washington/Redmond?forecast=today");
UriTemplateMatch results = template.Match(prefix, fullUri);

Console.WriteLine("Matching {0} to {1}", template.ToString(), fullUri.ToString());

if (results != null)
{
foreach (string variableName in results.BoundVariables.Keys)
{
Console.WriteLine(" {0}: {1}", variableName, results.BoundVariables[variableName]);
}
}
机器人 2012-04-04
  • 打赏
  • 举报
回复
用 UriBuilder 比较合适。
dalmeeme 2012-04-04
  • 打赏
  • 举报
回复
正则表达式,或Uri类下面的属性+Split方法.
threenewbee 2012-04-04
  • 打赏
  • 举报
回复
非常简单。实际上似乎没有什么编程语言做这个有困难吧。除非你硬要用sql来做。
hch126163 2012-04-04
  • 打赏
  • 举报
回复
字符串 处理

Split 函数就可以了

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧