You are trying to upload content to a server that most likely does not accept unauthorized uploads (as you are doing by sending a POST request). You need to use DownloadStringAsync instead.
Call url without parameter with webclient
-
10-06-2023 - |
質問
I am working on my project.I need to pass URL without parameter with Webclient.
WebClient webClient = new WebClient();
webClient.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
var uri = new Uri("http://misteducation.org/getques.php/testlist", UriKind.Absolute);
webClient.UploadStringCompleted += new UploadStringCompletedEventHandler(webClient_UploadStringCompleted);
webClient.UploadProgressChanged += webClient_UploadProgressChanged;
webClient.UploadStringAsync(uri,"POST",string.Empty);
I am using this code, but I am getting an exception.
解決
他のヒント
From what I see, you may be trying to download string rather than upload. In that case, you can use either DownloadStringCompleted and its appropriate handler OR DownloadStringAsync which I would personally recommend .
所属していません StackOverflow