FileWebRequest Sınıf
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
sınıfının dosya sistemi uygulamasını WebRequest sağlar.
public ref class FileWebRequest : System::Net::WebRequest, System::Runtime::Serialization::ISerializable
public ref class FileWebRequest : System::Net::WebRequest
public class FileWebRequest : System.Net.WebRequest, System.Runtime.Serialization.ISerializable
[System.Serializable]
public class FileWebRequest : System.Net.WebRequest, System.Runtime.Serialization.ISerializable
public class FileWebRequest : System.Net.WebRequest
type FileWebRequest = class
inherit WebRequest
interface ISerializable
[<System.Serializable>]
type FileWebRequest = class
inherit WebRequest
interface ISerializable
Public Class FileWebRequest
Inherits WebRequest
Implements ISerializable
Public Class FileWebRequest
Inherits WebRequest
- Devralma
- Öznitelikler
- Uygulamalar
Örnekler
Aşağıdaki kod örneği, bir dosya sistemi kaynağına erişmek için sınıfını FileWebRequest kullanır.
// This example creates or opens a text file and stores a string in it.
// Both the file and the string are passed by the user.
// Note. For this program to work, the folder containing the test file
// must be shared, with its permissions set to allow write access.
using System.Net;
using System;
using System.IO;
using System.Text;
namespace Mssc.PluggableProtocols.File
{
class TestGetRequestStream
{
private static FileWebRequest myFileWebRequest;
private static void showUsage ()
{
Console.WriteLine ("\nPlease enter file name and timeout :");
Console.WriteLine ("Usage: cs_getrequeststream <systemname>/<sharedfoldername>/<filename> timeout");
Console.WriteLine ("Example: cs_getrequeststream ngetrequestrtream() ndpue/temp/hello.txt 1000");
Console.WriteLine ("Small time-out values (for example, 3 or less) cause a time-out exception.");
}
private static void makeFileRequest (string fileName, int timeout)
{
try
{
// Create a Uri object.
Uri myUrl = new Uri ("file://" + fileName);
// Create a FileWebRequest object.
myFileWebRequest = (FileWebRequest)WebRequest.CreateDefault (myUrl);
// Set the time-out to the value selected by the user.
myFileWebRequest.Timeout = timeout;
// Set the Method property to POST
myFileWebRequest.Method = "POST";
}
catch (WebException e)
{
Console.WriteLine ("WebException: " + e.Message);
}
catch (UriFormatException e)
{
Console.WriteLine ("UriFormatWebException: " + e.Message);
}
}
private static void writeToFile ()
{
try
{
// Enter the string to write to the file.
Console.WriteLine ("Enter the string you want to write:");
string userInput = Console.ReadLine ();
// Convert the string to a byte array.
ASCIIEncoding encoder = new ASCIIEncoding ();
byte[] byteArray = encoder.GetBytes (userInput);
// Set the ContentLength property.
myFileWebRequest.ContentLength = byteArray.Length;
string contentLength = myFileWebRequest.ContentLength.ToString ();
Console.WriteLine ("\nThe content length is {0}.", contentLength);
// Get the file stream handler to write to the file.
Stream readStream = myFileWebRequest.GetRequestStream ();
// Write to the file stream.
// Note. For this to work, the file must be accessible
// on the network. This can be accomplished by setting the property
// sharing of the folder containg the file.
// FileWebRequest.Credentials property cannot be used for this purpose.
readStream.Write (byteArray, 0, userInput.Length);
Console.WriteLine ("\nThe String you entered was successfully written to the file.");
readStream.Close ();
}
catch (WebException e)
{
Console.WriteLine ("The WebException: " + e.Message);
}
catch (UriFormatException e)
{
Console.WriteLine ("The UriFormatWebException: " + e.Message);
}
}
public static void Main (String[] args)
{
if (args.Length < 2)
{
showUsage ();
}
else
{
makeFileRequest (args[0], int.Parse (args[1]));
writeToFile ();
}
}
}
}
'
' This example creates or opens a text file and stores a string in it.
' Both the file and the string are passed by the user.
' Note. For this program to work, the folder containing the test file
' must be shared, with its permissions set to allow write access.
Imports System.Net
Imports System.IO
Imports System.Text
Namespace Mssc.PluggableProtocols.File
Module TestGetRequestStream
Class TestGetRequestStream
Private Shared myFileWebRequest As FileWebRequest
' Show how to use this program.
Private Shared Sub showUsage()
Console.WriteLine(ControlChars.Lf + "Please enter file name and timeout :")
Console.WriteLine("Usage: vb_getrequeststream <systemname>/<sharedfoldername>/<filename> timeout")
Console.WriteLine("Example: vb_getrequeststream ngetrequestrtream() ndpue/temp/hello.txt 1000")
Console.WriteLine("Small time-out values (for example, 3 or less) cause a time-out exception.")
End Sub
Private Shared Sub makeFileRequest(ByVal fileName As String, ByVal timeout As Integer)
Try
' Create a Uri object.to access the file requested by the user.
Dim myUrl As New Uri("file://" + fileName)
' Create a FileWebRequest object.for the requeste file.
myFileWebRequest = CType(WebRequest.CreateDefault(myUrl), FileWebRequest)
' Set the time-out to the value selected by the user.
myFileWebRequest.Timeout = timeout
' Set the Method property to POST
myFileWebRequest.Method = "POST"
Catch e As WebException
Console.WriteLine(("WebException is: " + e.Message))
Catch e As UriFormatException
Console.WriteLine(("UriFormatWebException is: " + e.Message))
End Try
End Sub
Private Shared Sub writeToFile()
Try
' Enter the string to write to the file.
Console.WriteLine("Enter the string you want to write:")
Dim userInput As String = Console.ReadLine()
' Convert the string to a byte array.
Dim encoder As New ASCIIEncoding
Dim byteArray As Byte() = encoder.GetBytes(userInput)
' Set the ContentLength property.
myFileWebRequest.ContentLength = byteArray.Length
Dim contentLength As String = myFileWebRequest.ContentLength.ToString()
Console.WriteLine(ControlChars.Lf + "The content length is {0}.", contentLength)
' Get the file stream handler to write to the file.
Dim readStream As Stream = myFileWebRequest.GetRequestStream()
' Write to the stream.
' Note. For this to work the file must be accessible
' on the network. This can be accomplished by setting the property
' sharing of the folder containg the file.
' FileWebRequest.Credentials property cannot be used for this purpose.
readStream.Write(byteArray, 0, userInput.Length)
Console.WriteLine(ControlChars.Lf + "The String you entered was successfully written to the file.")
readStream.Close()
Catch e As WebException
Console.WriteLine(("WebException is: " + e.Message))
Catch e As UriFormatException
Console.WriteLine(("UriFormatWebException is: " + e.Message))
End Try
End Sub
Public Shared Sub Main(ByVal args() As String)
If args.Length < 2 Then
showUsage()
Else
makeFileRequest(args(0), Integer.Parse(args(1)))
writeToFile()
End If
End Sub
End Class
End Module
End Namespace
Açıklamalar
sınıfı, FileWebRequest yerel dosyaları istemek için düzenini kullanan file:// Tekdüzen Kaynak Tanımlayıcıları (URI' ler) için temel sınıfı uygularWebRequestabstract.
Oluşturucuyu FileWebRequest kullanmayın.
WebRequest.Create sınıfının yeni örneklerini FileWebRequest başlatmak için yöntemini kullanın. URI düzeni ise file://Create yöntemi bir FileWebRequest nesnesi döndürür.
yöntemi özelliğinde GetResponse belirtilen dosya için zaman uyumlu istekte RequestUri bulunur ve yanıtı içeren bir FileWebResponse nesne döndürür. ve EndGetResponse yöntemlerini kullanarak BeginGetResponse dosya için zaman uyumsuz istekte bulunabilirsiniz.
Bir dosyaya veri yazmak istediğinizde, GetRequestStream yöntemi yazabileceğiniz bir Stream örnek döndürür. BeginGetRequestStream ve EndGetRequestStream yöntemleri, yazma veri akışına zaman uyumsuz erişim sağlar.
sınıfı, FileWebRequest hata işleme ve kod erişimi güvenliği için sınıfına dayanır File .
Oluşturucular
| Name | Description |
|---|---|
| FileWebRequest(SerializationInfo, StreamingContext) |
Geçersiz.
Geçersiz.
Geçersiz.
ve StreamingContext sınıflarının FileWebRequest belirtilen örneklerinden SerializationInfo sınıfının yeni bir örneğini başlatır. |
Özellikler
| Name | Description |
|---|---|
| AuthenticationLevel |
Bu istek için kullanılan kimlik doğrulaması ve kimliğe bürünme düzeyini gösteren değerleri alır veya ayarlar. (Devralındığı yer: WebRequest) |
| CachePolicy |
Bu istek için önbellek ilkesini alır veya ayarlar. (Devralındığı yer: WebRequest) |
| ConnectionGroupName |
İstek için bağlantı grubunun adını alır veya ayarlar. Bu özellik gelecekte kullanılmak üzere ayrılmıştır. |
| ContentLength |
Gönderilen verilerin içerik uzunluğunu alır veya ayarlar. |
| ContentType |
Gönderilen verilerin içerik türünü alır veya ayarlar. Bu özellik gelecekte kullanılmak üzere ayrılmıştır. |
| CreatorInstance |
Geçersiz.
Bir alt sınıfta geçersiz kılındığında, belirtilen URI'ye WebRequest istekte bulunmak için örneği oluşturulurken kullanılan sınıftan türetilen IWebRequestCreate fabrika nesnesini alır. (Devralındığı yer: WebRequest) |
| Credentials |
Bu istekle ilişkili kimlik bilgilerini alır veya ayarlar. Bu özellik gelecekte kullanılmak üzere ayrılmıştır. |
| Headers |
İstekle ilişkili ad/değer çiftlerinin koleksiyonunu alır. Bu özellik gelecekte kullanılmak üzere ayrılmıştır. |
| ImpersonationLevel |
Geçerli istek için kimliğe bürünme düzeyini alır veya ayarlar. (Devralındığı yer: WebRequest) |
| Method |
İstek için kullanılan protokol yöntemini alır veya ayarlar. Bu özellik gelecekte kullanılmak üzere ayrılmıştır. |
| PreAuthenticate |
bir isteğin ön kimlik doğrulaması yapılıp yapılmayacağını belirten bir değer alır veya ayarlar. Bu özellik gelecekte kullanılmak üzere ayrılmıştır. |
| Proxy |
Bu istek için kullanılacak ağ proxy'sini alır veya ayarlar. Bu özellik gelecekte kullanılmak üzere ayrılmıştır. |
| RequestUri |
İsteğin Tekdüzen Kaynak Tanımlayıcısını (URI) alır. |
| Timeout |
İstek zaman aşımına gelene kadar olan süreyi alır veya ayarlar. |
| UseDefaultCredentials |
Her zaman bir NotSupportedExceptionatar. |
Yöntemler
| Name | Description |
|---|---|
| Abort() |
bir İnternet kaynağına yönelik isteği iptal eder. |
| Abort() |
İsteği durdurur. (Devralındığı yer: WebRequest) |
| BeginGetRequestStream(AsyncCallback, Object) |
Bir nesnenin veri yazmak için kullanması için zaman uyumsuz bir Stream istek başlatır. |
| BeginGetResponse(AsyncCallback, Object) |
Dosya sistemi kaynağı için zaman uyumsuz bir istek başlatır. |
| CreateObjRef(Type) |
Uzak bir nesneyle iletişim kurmak için kullanılan bir ara sunucu oluşturmak için gereken tüm ilgili bilgileri içeren bir nesne oluşturur. (Devralındığı yer: MarshalByRefObject) |
| EndGetRequestStream(IAsyncResult) |
Uygulamanın veri yazmak için kullandığı bir Stream örnek için zaman uyumsuz isteği sonlandırır. |
| EndGetResponse(IAsyncResult) |
Dosya sistemi kaynağı için zaman uyumsuz isteği sonlandırır. |
| Equals(Object) |
Belirtilen nesnenin geçerli nesneye eşit olup olmadığını belirler. (Devralındığı yer: Object) |
| GetHashCode() |
Varsayılan karma işlevi işlevi görür. (Devralındığı yer: Object) |
| GetLifetimeService() |
Geçersiz.
Bu örnek için yaşam süresi ilkesini denetleen geçerli yaşam süresi hizmet nesnesini alır. (Devralındığı yer: MarshalByRefObject) |
| GetObjectData(SerializationInfo, StreamingContext) |
Geçersiz.
hedef nesneyi seri hale getirmek için gereken verilerle doldurur SerializationInfo . |
| GetRequestStream() |
Dosya sistemi kaynağına veri yazmak için bir Stream nesne döndürür. |
| GetRequestStreamAsync() |
Zaman uyumsuz bir işlem olarak dosya sistemi kaynağına veri yazmak için bir akış döndürür. |
| GetRequestStreamAsync() |
Alt sınıfta geçersiz kılındığında, zaman uyumsuz bir işlem olarak İnternet kaynağına veri yazmak için bir döndürür Stream . (Devralındığı yer: WebRequest) |
| GetResponse() |
Dosya sistemi isteğine bir yanıt döndürür. |
| GetResponseAsync() |
Zaman uyumsuz bir işlem olarak dosya sistemi isteğine bir yanıt döndürür. |
| GetResponseAsync() |
Alt sınıfta geçersiz kılındığında, zaman uyumsuz bir işlem olarak İnternet isteğine bir yanıt döndürür. (Devralındığı yer: WebRequest) |
| GetType() |
Geçerli örneğin Type alır. (Devralındığı yer: Object) |
| InitializeLifetimeService() |
Geçersiz.
Bu örneğin yaşam süresi ilkesini denetlemek için bir yaşam süresi hizmet nesnesi alır. (Devralındığı yer: MarshalByRefObject) |
| MemberwiseClone() |
Geçerli Objectbasit bir kopyasını oluşturur. (Devralındığı yer: Object) |
| MemberwiseClone(Boolean) |
Geçerli MarshalByRefObject nesnenin sığ bir kopyasını oluşturur. (Devralındığı yer: MarshalByRefObject) |
| ToString() |
Geçerli nesneyi temsil eden bir dize döndürür. (Devralındığı yer: Object) |
Belirtik Arabirim Kullanımları
| Name | Description |
|---|---|
| ISerializable.GetObjectData(SerializationInfo, StreamingContext) |
Geçersiz.
bir SerializationInfo nesneyi serileştirmek FileWebRequestiçin gerekli verilerle doldurur. |