C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,203 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
How to get url after request using webclient upload file?
Exemple:
WebClient request = new WebClient();
request.UploadFile("https://sndup.net/", "C:\\Users\\sinxdesk\\Music\\558.mp3");
Result:
https://i.stack.imgur.com/CFBBt.png
I need to get this "https://sndup.net/9532" and put it on ClipBoard using C#
Thank you for your attention
WebClient
has been deprecated in favour of HttpClient
so I've added an example using that instead:
using System.Net;
const string filepath = @"C:\Users\sinxdesk\Music\558.mp3";
var filename = Path.GetFileNameWithoutExtension(filepath);
using HttpClient client = new HttpClient(new HttpClientHandler { AllowAutoRedirect = false });
using FileStream stream = new FileStream(filepath, FileMode.Open, FileAccess.Read);
var response = await client.PostAsync("https://sndup.net/", new MultipartFormDataContent {
{ new StreamContent(stream), "file", filename },
{ new StringContent(filename), "postname" }
});
if (response.StatusCode == HttpStatusCode.Found) {
var url = response.Headers.GetValues("Location").First();
Console.WriteLine(url);
}