Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何向httpwebrequest添加查询字符串_C#_.net - Fatal编程技术网

C# 如何向httpwebrequest添加查询字符串

C# 如何向httpwebrequest添加查询字符串,c#,.net,C#,.net,我想向httpwebrequest添加一些QueryString,但找不到任何属性?我记得我以前可以使用QueryString字典。添加查询字符串的最佳方法如下: var targetUri = new Uri("http://www.example.org?queryString=a&b=c"); var webRequest = (HttpWebRequest)WebRequest.Create(targetUri); var webRequestResponse = webReq

我想向httpwebrequest添加一些QueryString,但找不到任何属性?我记得我以前可以使用QueryString字典。

添加查询字符串的最佳方法如下:

var targetUri = new Uri("http://www.example.org?queryString=a&b=c");
var webRequest = (HttpWebRequest)WebRequest.Create(targetUri);

var webRequestResponse = webRequest.GetResponse();

请记住:如果您使用用户输入来构造Uri,请确保验证它、转义它并且不信任它。

我不明白您的意思。只需在url中输入参数名称和值并执行请求,页面/响应就可以访问querystring字典并使用它。但是如果我想稍后添加查询字符串,该怎么办。。??e、 g
HttpWebRequestObject
已经初始化,我想在Uri中为查询字符串@Rob添加一些内容,不要忘记在注释中添加标记response@ShashwatTripathi,因为
RequestUri
属性是只读的,
Request.Uri
上的
Query
属性也是只读的,我想答案是你不能。我找不到扩展现有请求的方法,因此如果我想附加请求,就不得不从头开始重新创建请求。