处理带变量名的URL,用C#是否能行?解决思路
处理带变量名的URL,用C#是否能行?
有个页面,上面有很多链接
带了变量名的那种,比如
'http://'+sURL+'defaulthmr.asp?popmembers=' + pID + '&isb=0&lng=' + sLNG
变量很多都是在js 文件里面定义的
我需要找到对应的,需要的url 并且发送get
这种链接用C#处理是否方便?大概的做法是如何?
我对C# 不是太熟悉,不知道我的描述是否已经清晰
先谢谢大家
------解决方案--------------------
字符串 处理
Split 函数就可以了
------解决方案--------------------
非常简单。实际上似乎没有什么编程语言做这个有困难吧。除非你硬要用sql来做。
------解决方案--------------------
正则表达式,或Uri类下面的属性+Split方法.
------解决方案--------------------
用 UriBuilder 比较合适。
------解决方案--------------------
UriTemplate 类
有个页面,上面有很多链接
带了变量名的那种,比如
'http://'+sURL+'defaulthmr.asp?popmembers=' + pID + '&isb=0&lng=' + sLNG
变量很多都是在js 文件里面定义的
我需要找到对应的,需要的url 并且发送get
这种链接用C#处理是否方便?大概的做法是如何?
我对C# 不是太熟悉,不知道我的描述是否已经清晰
先谢谢大家
------解决方案--------------------
字符串 处理
Split 函数就可以了
------解决方案--------------------
非常简单。实际上似乎没有什么编程语言做这个有困难吧。除非你硬要用sql来做。
------解决方案--------------------
正则表达式,或Uri类下面的属性+Split方法.
------解决方案--------------------
用 UriBuilder 比较合适。
------解决方案--------------------
UriTemplate 类
- C# code
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]); } }