Answers for "webrequest in c#"

C#
0

how to make a webrequest in c#

Uri ourUri = new Uri(url);            

// Create a 'WebRequest' object with the specified url. 
WebRequest myWebRequest = WebRequest.Create(url); 

// Send the 'WebRequest' and wait for response.
WebResponse myWebResponse = myWebRequest.GetResponse(); 

// Use "ResponseUri" property to get the actual Uri from where the response was attained.
if (ourUri.Equals(myWebResponse.ResponseUri))
    Console.WriteLine("nRequest Url : {0} was not redirected",url);   
else
    Console.WriteLine("nRequest Url : {0} was redirected to {1}",url,myWebResponse.ResponseUri);   
// Release resources of response object.
myWebResponse.Close();

// IGNORE - RC
Posted by: Guest on July-13-2021
0

.net core c# webrequest download

byte[] listeByte;
            try
            {
                
                FtpWebRequest requestFichier = (FtpWebRequest)WebRequest.Create(@filePath);
                requestFichier.Credentials = new NetworkCredential(utilisateur, motDePasse);
                requestFichier.Method = WebRequestMethods.Ftp.DownloadFile;
                using (WebResponse response = await requestFichier.GetResponseAsync())
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        response.GetResponseStream().CopyTo(ms);
                        listeByte = ms.ToArray();
                    }
                }
            }
            catch (Exception ex)
            {
               throw ex;
            }

            return listeByte;
Posted by: Guest on March-05-2020

C# Answers by Framework

Browse Popular Code Answers by Language