当前位置: 首页>>代码示例>>C#>>正文


C# Net.WebRequest类代码示例

本文整理汇总了C#中System.Net.WebRequest的典型用法代码示例。如果您正苦于以下问题:C# WebRequest类的具体用法?C# WebRequest怎么用?C# WebRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


WebRequest类属于System.Net命名空间,在下文中一共展示了WebRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetResponse

 public GetResponse( WebRequest request ) :
     base(request)
 {
     SortedList metadata = extractMetadata( response );
     string body = Utils.slurpInputStream( response.GetResponseStream() );
     this.obj = new S3Object( body, metadata );
 }
开发者ID:nuxleus,项目名称:Nuxleus.Extf,代码行数:7,代码来源:GetResponse.cs

示例2: CopyHttpRequestProps

        private static void CopyHttpRequestProps (WebRequest source, WebRequest copy)
        {
            var httpSource = source as HttpWebRequest;
            if (httpSource == null)
                return;

            var httpCopy = (HttpWebRequest)copy;
            //httpCopy.Accept = httpSource.Accept;
            //httpCopy.Connection = httpSource.Connection;
            //httpCopy.ContentLength = httpSource.ContentLength;
            //httpCopy.Date = httpSource.Date;
            //httpCopy.Expect = httpSource.Expect;
            //httpCopy.Host = httpSource.Host;
            //httpCopy.IfModifiedSince = httpSource.IfModifiedSince;
            //httpCopy.Referer = httpSource.Referer;
            //httpCopy.TransferEncoding = httpSource.TransferEncoding;
            //httpCopy.UserAgent = httpSource.UserAgent;
            httpCopy.AllowAutoRedirect = httpSource.AllowAutoRedirect;
            httpCopy.AllowReadStreamBuffering = httpSource.AllowReadStreamBuffering;
            httpCopy.AllowWriteStreamBuffering = httpSource.AllowWriteStreamBuffering;
            httpCopy.AutomaticDecompression = httpSource.AutomaticDecompression;
            httpCopy.ClientCertificates = httpSource.ClientCertificates;
            httpCopy.ContinueTimeout = httpSource.ContinueTimeout;
            httpCopy.CookieContainer = httpSource.CookieContainer;
            httpCopy.KeepAlive = httpSource.KeepAlive;
            httpCopy.MaximumAutomaticRedirections = httpSource.MaximumAutomaticRedirections;
            httpCopy.MaximumResponseHeadersLength = httpSource.MaximumResponseHeadersLength;
            httpCopy.MediaType = httpSource.MediaType;
            httpCopy.Pipelined = httpSource.Pipelined;
            httpCopy.ProtocolVersion = httpSource.ProtocolVersion;
            httpCopy.ReadWriteTimeout = httpSource.ReadWriteTimeout;
            httpCopy.SendChunked = httpSource.SendChunked;
            httpCopy.ServerCertificateValidationCallback = httpSource.ServerCertificateValidationCallback;
            httpCopy.UnsafeAuthenticatedConnectionSharing = httpSource.UnsafeAuthenticatedConnectionSharing;
        }
开发者ID:binki,项目名称:Alba.Framework,代码行数:35,代码来源:WebRequestExts.cs

示例3: SignRequestLite

        public void SignRequestLite(WebRequest webRequest)
        {
            if (webRequest == null)
                throw new ArgumentNullException("webRequest");

            webRequest.Headers[this.headerName] = this.headerValue();
        }
开发者ID:WindowsAzure-Toolkits,项目名称:wa-toolkit-wp-nugets,代码行数:7,代码来源:StorageCredentialsCustomHeader.cs

示例4: StartAsync

        public void StartAsync(HttpContext context, string url)
        {
            this.m_context = context;

            this.m_request = HttpWebRequest.Create(url);
            this.m_request.BeginGetResponse(this.EndGetResponseCallback, null);
        }
开发者ID:JeffreyZhao,项目名称:java-vs-csharp,代码行数:7,代码来源:WebAsyncTransfer.cs

示例5: RequestState

 public RequestState(WebRequest request)
 {
     BufferRead = new byte[BUFFER_SIZE];
     RequestData = new StringBuilder(String.Empty);
     Request = request;
     ResponseStream = null;
 }
开发者ID:bolthar,项目名称:tenteikura,代码行数:7,代码来源:RequestState.cs

示例6: HttpJsonRequest

 public HttpJsonRequest(string url, string method, JObject metadata)
 {
     webRequest = WebRequest.Create(url);
     WriteMetadata(metadata);
     webRequest.Method = method;
     webRequest.ContentType = "application/json";
 }
开发者ID:torkelo,项目名称:ravendb,代码行数:7,代码来源:HttpJsonRequest.cs

示例7: attemptConnection

        //---------------------------------------------------
        // @Name:		attemptConnection
        // @Author:		Lane - PeePeeSpeed
        // @Inputs:		string url, string queue
        // @Outputs:	NULL
        //
        // @Desc:		Attempts to create a connection
        //                to the server for data transfer.
        //---------------------------------------------------
        public void attemptConnection(string u, string q)
        {
            try
            {
                wrGetUrl = WebRequest.Create(u + "?cmd=get&Value=" + q);
                objStream = wrGetUrl.GetResponse().GetResponseStream();
                objReader = new StreamReader(objStream);

                //assert here?
            }
            catch (System.Net.WebException)
            {
                DialogResult dialogResult = MessageBox.Show("Could not establish connection to server\n\nDo you want to try again? System will exit on No.", "Error", MessageBoxButtons.YesNo);

                switch (dialogResult)
                {
                    case DialogResult.Yes:
                        attemptConnection(u, q);
                        break;
                    case DialogResult.No:
                        System.Environment.Exit(0);
                        break;
                }
            }
        }
开发者ID:MJRule,项目名称:MotionProject,代码行数:34,代码来源:NetworkModel.cs

示例8: ListAllMyBucketsResponse

        public ListAllMyBucketsResponse( WebRequest request )
            : base(request)
        {
            buckets = new ArrayList();
            string rawBucketXML = Utils.slurpInputStreamAsString( response.GetResponseStream() );

            XmlDocument doc = new XmlDocument();
            doc.LoadXml( rawBucketXML );
            foreach (XmlNode node in doc.ChildNodes)
            {
                if (node.Name.Equals("ListAllMyBucketsResult"))
                {
                    foreach (XmlNode child in node.ChildNodes)
                    {
                        if (child.Name.Equals("Owner"))
                        {
                            owner = new Owner(child);
                        }
                        else if (child.Name.Equals("Buckets"))
                        {
                            foreach (XmlNode bucket in child.ChildNodes)
                            {
                                if (bucket.Name.Equals("Bucket"))
                                {
                                    buckets.Add(new Bucket(bucket));
                                }
                            }
                        }
                    }
                }
            }
        }
开发者ID:njmube,项目名称:AmazonS3DA,代码行数:32,代码来源:ListAllMyBucketsResponse.cs

示例9: Invoke

        internal bool Invoke(string hostName,
                             ServicePoint servicePoint,
                             X509Certificate certificate,
                             WebRequest request,
                             X509Chain chain,
                             SslPolicyErrors sslPolicyErrors)
        {
            PolicyWrapper policyWrapper = new PolicyWrapper(m_CertificatePolicy,
                                                            servicePoint,
                                                            (WebRequest) request);

            if (m_Context == null)
            {
                return policyWrapper.CheckErrors(hostName,
                                                 certificate,
                                                 chain,
                                                 sslPolicyErrors);
            }
            else
            {
                ExecutionContext execContext = m_Context.CreateCopy();
                CallbackContext callbackContext = new CallbackContext(policyWrapper,
                                                                      hostName,
                                                                      certificate,
                                                                      chain,
                                                                      sslPolicyErrors);
                ExecutionContext.Run(execContext, Callback, callbackContext);
                return callbackContext.result;
            }
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:30,代码来源:ServicePointManager.cs

示例10: AuthenticateCore

        /// <summary>
        /// Authorizes the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        protected override void AuthenticateCore(WebRequest context)
        {
            context = Enforce.NotNull(context, () => context);

            // Authorize the request.
            context.Credentials = this.Credentials;
        }
开发者ID:peterbucher,项目名称:silkveil,代码行数:11,代码来源:FtpAuthentication.cs

示例11: Request

 private Request(string url, HttpMethod httpMethod, string entity = null)
 {
     _url = url;
     _httpMethod = httpMethod;
     _entity = entity;
     _webRequest = CreateWebRequest(_url, _entity, _httpMethod);
 }
开发者ID:bnathyuw,项目名称:nonae,代码行数:7,代码来源:Request.cs

示例12: SetCorrelationContextForWebRequest

        /// <summary>
        /// Populates WebRequest using the operation context in telemetry item.
        /// </summary>
        /// <param name="dependencyTelemetry">Dependency telemetry item.</param>
        /// <param name="webRequest">Http web request.</param>
        internal static void SetCorrelationContextForWebRequest(DependencyTelemetry dependencyTelemetry, WebRequest webRequest)
        {
            if (dependencyTelemetry == null)
            {
                throw new ArgumentNullException("dependencyTelemetry");
            }

            if (webRequest != null)
            {
                OperationContext context = dependencyTelemetry.Context.Operation;

                if (!string.IsNullOrEmpty(context.Id))
                {
                    webRequest.Headers.Add(RequestResponseHeaders.StandardRootIdHeader, context.Id);
                }

                if (!string.IsNullOrEmpty(dependencyTelemetry.Id))
                {
                    webRequest.Headers.Add(RequestResponseHeaders.StandardParentIdHeader, dependencyTelemetry.Id);
                }
            }
            else
            {
                DependencyCollectorEventSource.Log.WebRequestIsNullWarning();
            }
        }
开发者ID:Microsoft,项目名称:ApplicationInsights-dotnet-server,代码行数:31,代码来源:WebRequestDependencyTrackingHelpers.cs

示例13: Authenticate

		public Authorization Authenticate (string challenge, WebRequest webRequest, ICredentials credentials) 
		{
			if (authObject == null)
				return null;

			return authObject.Authenticate (challenge, webRequest, credentials);
		}
开发者ID:runefs,项目名称:Marvin,代码行数:7,代码来源:NtlmClient.cs

示例14: InternalAuthenticate

		static Authorization InternalAuthenticate (WebRequest webRequest, ICredentials credentials)
		{
			HttpWebRequest request = webRequest as HttpWebRequest;
			if (request == null || credentials == null)
				return null;

			NetworkCredential cred = credentials.GetCredential (request.AuthUri, "basic");
			if (cred == null)
				return null;

			string userName = cred.UserName;
			if (userName == null || userName == "")
				return null;

			string password = cred.Password;
			string domain = cred.Domain;
			byte [] bytes;

			// If domain is set, MS sends "domain\user:password". 
			if (domain == null || domain == "" || domain.Trim () == "")
				bytes = GetBytes (userName + ":" + password);
			else
				bytes = GetBytes (domain + "\\" + userName + ":" + password);

			string auth = "Basic " + Convert.ToBase64String (bytes);
			return new Authorization (auth);
		}
开发者ID:stabbylambda,项目名称:mono,代码行数:27,代码来源:BasicClient.cs

示例15: GetWebResponse

 // Overrides WebClien'ts GetWebResponse to add response cookies to the cookie container
 protected override WebResponse GetWebResponse(WebRequest request, IAsyncResult result)
 {
     WebResponse response = base.GetWebResponse(request, result);
     ReadCookies(response);
     responseURL = response.ResponseUri;
     return response;
 }
开发者ID:andrewzach,项目名称:Blackboard-Downloader,代码行数:8,代码来源:WebClientEx.cs


注:本文中的System.Net.WebRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。