C#如何在问号后读取URL? [英] C# How to read a URL after a question mark?
问题描述
你好,
使用C#,我使用网络浏览器"来导航到特定的URL.
但是,当我单击浏览器上的某个按钮时,会打开一个新页面,我需要获取该页面的会话ID(换句话说,问号后的部分). br/>
新页面的URL在下面.
www.fbwebpos.com/finans/report/transaction.search? < b> OWASP_CSRFTOKEN = ZSOT-CPUM-N32D [ www.fbwebpos.com/finans/report/transaction.search [ ^ ]
webBrowser1.Url.Query.ToString()
返回空.
谢谢.
Hello,
Using C# I''m using a ''webbrowser'' to navigate to particular URLs.
However, when I clicked on a certain button on the browser, a new page is opened and I need to get the session id (in other words, the part after the question mark) of this page.
The URL of the new page is below.
www.fbwebpos.com/finans/report/transaction.search?<b>OWASP_CSRFTOKEN=ZSOT-CPUM-N32D[^]
webBrowser.Url.ToString()
only returns: www.fbwebpos.com/finans/report/transaction.search[^]
webBrowser1.Url.Query.ToString()
returns empty.
Thank you.
推荐答案
尝试Request.Querystring提取这些值
这是一个示例 [
try Request.Querystring to extract those values
Here is a sample[^]
Regards
Sebastian
您可以尝试以下操作:
you can try this:
string value=Request.QueryString["OWASP_CSRFTOKEN"];
为"Navigated"事件添加处理程序:
Add a handler for ''Navigated'' event:
private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e)
{
string query = e.Url.Query;
}
这将为您提供URL的查询字符串部分,包括开始时的问号.
或者,您可以使用:
This will give you query string part of URL including the question mark at start.
Alternatively you can use:
webBrowser1.Document.Url.Query
但是您必须确保浏览器完成了文档的加载.
but you''ll have to make sure the browser finished loading the document.
这篇关于C#如何在问号后读取URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!