• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Net.WebRequest类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: InitiateRequest

 static WebResponse InitiateRequest(WebRequest request)
 {
     var response = request.GetResponse();
     var status = ((HttpWebResponse)response).StatusCode;
     if (Convert.ToInt32(status) >= 400) throw new Exception("Error making request");
     return response;
 }
开发者ID:benjaminkeeping,项目名称:agilex.json.client,代码行数:7,代码来源:RawClient.cs


示例17: UpdateHeaders

		public void UpdateHeaders(WebRequest webRequest)
		{
			if (operationsHeadersDictionary != null)
			{
				foreach (var kvp in operationsHeadersDictionary)
				{
					webRequest.Headers[kvp.Key] = kvp.Value;
				}
			}
			if(operationsHeadersColletion != null)
			{
				foreach (string header in operationsHeadersColletion)
				{
					try
					{
						webRequest.Headers[header] = operationsHeadersColletion[header];
					}
					catch (Exception e)
					{
						throw new InvalidOperationException(
							"Failed to set header '" + header + "' to the value: " + operationsHeadersColletion[header], e);
					}
				}
			}
		}
开发者ID:arelee,项目名称:ravendb,代码行数:25,代码来源:CreateHttpJsonRequestParams.cs


示例18: SendHttpGet

        public static string SendHttpGet(WebRequest request, YahooMessengerAuthentication authentication)
        {
            request.Method = "GET";

            if(authentication!=null)
            {
                if(!authentication.IsUsingOAuth)
                    request.Headers.Add("Cookie",authentication.Cookie);
                else request.Headers.Add("Authorization", "OAuth");
            }

            using(var response = (HttpWebResponse)request.GetResponse())
            {
                if(response == null) throw new NullReferenceException();

                var respCode = response.StatusCode;

                if (respCode != HttpStatusCode.OK)
                    throw new HttpException(HttpException.HTTP_OK_NOT_RECEIVED, respCode.ToString());

                var dataStream = response.GetResponseStream();

                if (dataStream == null) throw new NullReferenceException();
                var reader = new StreamReader(dataStream);

                // Read the content.
                var responseFromServer = new StringBuilder("");
                responseFromServer.Append(reader.ReadToEnd());
                reader.Close();
                dataStream.Close();
                response.Close();

                return responseFromServer.ToString();
            }
        }
开发者ID:PhanQuang,项目名称:Yahoo-Messenger-API,代码行数:35,代码来源:HttpUtils.cs


示例19: ExecuteWebRequest

        private static string ExecuteWebRequest(WebRequest webRequest)
        {
            try
            {
                using (var response = webRequest.GetResponse())
                {
                    return ReadStream(response.GetResponseStream());
                }
            }
            catch (WebException webException)
            {
                if (webException.Response != null)
                {
                    var statusCode = ((HttpWebResponse)webException.Response).StatusCode;

                    var romitError = new RomitError();

                    if (webRequest.RequestUri.ToString().Contains("oauth"))
                        romitError = Mapper<RomitError>.MapFromJson(ReadStream(webException.Response.GetResponseStream()));
                    else
                        romitError = Mapper<RomitError>.MapFromJson(ReadStream(webException.Response.GetResponseStream()), "error");

                    throw new RomitException(statusCode, romitError, romitError.Message);
                }

                throw;
            }
        }
开发者ID:spoiledtechie,项目名称:Romit.Net,代码行数:28,代码来源:Requestor.cs


示例20: SendHttpPost

        public static string SendHttpPost(WebRequest request, YahooMessengerAuthentication authentication, string content)
        {
            request.Method = "POST";
            byte[] byteArray = Encoding.UTF8.GetBytes(content);
            request.ContentLength = byteArray.Length;
            var dataStream = request.GetRequestStream();
            // Write the data to the request stream.
            dataStream.Write(byteArray, 0, byteArray.Length);
            // Close the Stream object.
            dataStream.Close();
            using(var response = (HttpWebResponse) request.GetResponse())
            {
                if (response == null) throw new NullReferenceException();

                var respCode = response.StatusCode;

                if (respCode != HttpStatusCode.OK)
                    throw new HttpException(HttpException.HTTP_OK_NOT_RECEIVED, respCode.ToString());

                dataStream = response.GetResponseStream();
                if (dataStream == null) throw new NullReferenceException();
                var reader = new StreamReader(dataStream);

                var responseFromServer = new StringBuilder("");
                responseFromServer.Append(reader.ReadToEnd());
                reader.Close();
                dataStream.Close();
                response.Close();

                return responseFromServer.ToString();
            }
        }
开发者ID:PhanQuang,项目名称:Yahoo-Messenger-API,代码行数:32,代码来源:HttpUtils.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Net.WebResponse类代码示例发布时间:2022-05-26
下一篇:
C# Net.WebProxy类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap