简体   繁体   English

如何将我的Webclient转换为发送Post请求而不是Get请求

[英]how to convert my Webclient to send Post request instead of Get request

I am working on an asp.net mvc-5 web application. 我正在处理一个asp.net mvc-5 Web应用程序。 and I have the following WebClient which will send a Get request as follow:- 并且我有以下WebClient,它将发送Get请求,如下所示:

using (WebClient wc = new WebClient())
            {
                string url = currentURL+ "home/scanserver?FQDN=allscan";
                wc.Headers.Add("Authorization", token);
                var json =wc.DownloadStringTaskAsync(url);
               TempData["messagePartial"] = string.Format("Scan has been completed. Scan reported generated");

            }

so can anyone advice how I can force my webclient to send Post request instead of Get request, while sending the same token (inside the request header) + FQDN parameter ? 所以任何人都可以建议我如何强制我的Web客户端发送Post请求而不是Get请求,同时发送相同的令牌(在请求标头内)+ FQDN参数?

Use UploadStringTaskAsync instead of DownloadStringTaskAsync . 使用UploadStringTaskAsync而不是DownloadStringTaskAsync

   var url = currentURL+ "home/scanserver";
   wc.Headers.Add("Authorization", token);
   var json =wc.UploadStringTaskAsync(url, "FQDN=allscan");

NOTE that json is a Task<string> not a string . 注意 jsonTask<string>而不是string Are you sure that you want to use async behaviour? 您确定要使用异步行为吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM