本文整理汇总了C#中WebRequest.Create方法的典型用法代码示例。如果您正苦于以下问题:C# WebRequest.Create方法的具体用法?C# WebRequest.Create怎么用?C# WebRequest.Create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WebRequest
的用法示例。
在下文中一共展示了WebRequest.Create方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetFile
private static string GetFile(DownloaderParams info)
{
string writePath = info.FullLocalPath;
if (!IsValidPath(writePath))
{
Debug.Fail("Generated invalid paths.");
return null;
}
string directory = Path.GetDirectoryName(writePath);
//if (WriteAccess(writePath))
//{
// Debug.WriteLine("I have write access");
//}
//else
//{
// Debug.WriteLine("I don't have write access");
//}
if (!FileSystem.DirectoryExists(directory))
{
FileSystem.CreateDirectory(directory);
}
//check for existence of local file
bool localFileExists = FileSystem.FileExists(writePath);
if (localFileExists)
{
return writePath;
}
var webRequest = new WebRequest();
IHttpWebResponse response;
IHttpWebRequest request = webRequest.Create(new Uri(info.RemoteUrl));
try
{
response = request.GetResponse();
}
catch (WebException ex)
{
response = ex.Response as System.Net.HttpWebResponse == null
? null
: new HttpWebResponse(ex.Response as System.Net.HttpWebResponse);
}
if (response == null)
{
return null;
}
if (response.StatusCode == HttpStatusCode.OK)
{
ReadResponseToFileStream(writePath, response);
return writePath;
}
return null;
}