質問

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.

役に立ちましたか?

解決

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.

他のヒント

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 .

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top