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


C# WebRequest.BeginGetRequestStream方法代码示例

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


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

示例1: SendRequest

        public void SendRequest(string postRequest, Microsoft.Phone.Controls.PerformanceProgressBar performanceProgressBar)
        {
            var bw = new System.ComponentModel.BackgroundWorker();
            bw.DoWork += (s, args) => // This runs on a background thread.
            {
                System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    performanceProgressBar.IsIndeterminate = true;
                    performanceProgressBar.Visibility = System.Windows.Visibility.Visible;
                });

                this.parameters = postRequest;
                this.request = WebRequest.Create(new Uri("http://192.168.1.71:8080/MobileApplication/mythapi")) as WebRequest;
                request.Method = "POST";
                request.ContentType = "application/x-www-form-urlencoded";
                request.BeginGetRequestStream(ReadCallback, request);
            };
            bw.RunWorkerCompleted += (s, args) =>
            {
                // Do your UI work here this will run on the UI thread.
                // Clear progress bar.
                performanceProgressBar.IsIndeterminate = false;
                performanceProgressBar.Visibility = System.Windows.Visibility.Collapsed;
            };
            bw.RunWorkerAsync();
        }
开发者ID:asdForever,项目名称:GeneralThings,代码行数:26,代码来源:Networking.cs

示例2: UploadAsync

        public void UploadAsync(string serverUrl, Action<string> callback)
        {
            var uri = new Uri(string.Format("{0}{1}?token={2}", serverUrl, Constants.UploadItemUrl, _token.Token), UriKind.Absolute);

            _webRequest = Create(uri);
            ((HttpWebRequest)_webRequest).AllowWriteStreamBuffering = true;
            _webRequest.Method = "POST";
            _webRequest.ContentType = "multipart/form-data; boundary=" + _boundary;
            _webRequest.BeginGetRequestStream(asyncResult => GetValue(asyncResult, callback), null);
        }
开发者ID:yutian130,项目名称:ArcGIS-Server-Admin-SDK,代码行数:10,代码来源:UploadFormDataRequest.cs

示例3: BeginRequest

 private static void BeginRequest(WebRequest request, Action<HttpStatusCode, string, OAuthTokens> onComplete, Action<Uri, Exception> onError, string data)
 {
     request.Method = "POST";
     request.ContentType = "application/x-www-form-urlencoded";
     request.BeginGetRequestStream(HandleRequestCallback,
                                    new RequestContext<string, OAuthTokens>
                                    {
                                        Body = data,
                                        Request = request,
                                        OnComplete = onComplete,
                                        OnError = onError
                                    });
 }
开发者ID:johnazariah,项目名称:pelican,代码行数:13,代码来源:OAuthRequestHandler.cs

示例4: GetRequestStreamInternal

        private static Stream GetRequestStreamInternal(WebRequest request)
        {
            // build the envent
			using (var revent = new ManualResetEvent(false))
			{
				// start the async call
				IAsyncResult result = request.BeginGetRequestStream(CallStreamCallback, revent);

				// wait for event
				revent.WaitOne();

				// return data stream
				return request.EndGetRequestStream(result);
			}
        }        
开发者ID:haoasqui,项目名称:ONLYOFFICE-Server,代码行数:15,代码来源:WebRequestStreamHelper.cs

示例5: RequestAsync

        private static void RequestAsync(WebRequest request, byte[] bodyBytes, Action<TrackResult> callback)
        {
            request.BeginGetRequestStream((r1) =>
            {
                try
                {
                    var stream = request.EndGetRequestStream(r1);
                    stream.BeginWrite(bodyBytes, 0, bodyBytes.Length, (r2) =>
                    {
                        try
                        {
                            stream.EndWrite(r2);
                            stream.Dispose();

                            request.BeginGetResponse((r3) =>
                            {
                                try
                                {
                                    using (var response = request.EndGetResponse(r3))
                                    {
                                        using (var reader = new StreamReader(response.GetResponseStream()))
                                        {
                                            if (callback != null)
                                                callback(new TrackResult(reader.ReadToEnd()));
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    HandleError(callback, ex);
                                }
                            }, null);
                        }
                        catch (Exception ex)
                        {
                            HandleError(callback, ex);
                        }
                    }, null);
                }
                catch(Exception ex)
                {
                    HandleError(callback, ex);
                }
            }, null);
        }
开发者ID:gsdean,项目名称:Mixpanel.NET,代码行数:45,代码来源:MixpanelAsyncHttp.cs

示例6: getRequestStream

        private static Stream getRequestStream(WebRequest request)
        {
            Stream requestStream = null;
            ManualResetEvent getRequestFinished = new ManualResetEvent(false);

            AsyncCallback callBack = new AsyncCallback(ar =>
            {
                var req = (HttpWebRequest)ar.AsyncState;
                requestStream = req.EndGetRequestStream(ar);
                getRequestFinished.Set();
            });

            var async = request.BeginGetRequestStream(callBack, request);

            getRequestFinished.WaitOne();

            return requestStream;
        }
开发者ID:ranjancse26,项目名称:fhir-net-api,代码行数:18,代码来源:WebRequestExtensions.cs

示例7: Start

 private void Start()
 {
     try
     {
         request = System.Net.WebRequest.Create(requestURI);
         request.Proxy = System.Net.GlobalProxySelection.GetEmptyWebProxy();
         if (null != postData)
         {
             request.ContentLength = postData.Length;
             request.ContentType = "application/x-www-form-urlencoded";
             request.Method = "POST";
             request.BeginGetRequestStream(new AsyncCallback(GetRequestCallback), request);
         }
         else
         {
             request.Method = "GET";
             request.BeginGetResponse(new AsyncCallback(GetResponseCallback), request);
         }
     }
     catch (OutOfMemoryException e)
     {
         if (retryCount < retryMax)
         {
             System.Diagnostics.Debug.WriteLine(e.Message);
             ++retryCount;
             Random random = new Random();
             Thread.Sleep(retryDelay * random.Next(retryCount * retryCount));
             Start();
         }
         else
         {
             OnException(e);
         }
     }
     catch (Exception e)
     {
         OnException(e);
     }
 }
开发者ID:MetricWise,项目名称:vtwsclib.NET,代码行数:39,代码来源:WebServiceAsyncRequest.cs

示例8: BeginProcessRequest

		void BeginProcessRequest (HttpChannelRequestAsyncResult result)
		{
			Message message = result.Message;
			TimeSpan timeout = result.Timeout;
			// FIXME: is distination really like this?
			Uri destination = message.Headers.To;
			if (destination == null) {
				if (source.Transport.ManualAddressing)
					throw new InvalidOperationException ("When manual addressing is enabled on the transport, every request messages must be set its destination address.");
				 else
				 	destination = Via ?? RemoteAddress.Uri;
			}

			web_request = HttpWebRequest.Create (destination);
			web_request.Method = "POST";
			web_request.ContentType = Encoder.ContentType;

#if NET_2_1
			var cmgr = source.GetProperty<IHttpCookieContainerManager> ();
			if (cmgr != null)
				((HttpWebRequest) web_request).CookieContainer = cmgr.CookieContainer;
#endif

#if !MOONLIGHT // until we support NetworkCredential like SL4 will do.
			// client authentication (while SL3 has NetworkCredential class, it is not implemented yet. So, it is non-SL only.)
			var httpbe = (HttpTransportBindingElement) source.Transport;
			string authType = null;
			switch (httpbe.AuthenticationScheme) {
			// AuthenticationSchemes.Anonymous is the default, ignored.
			case AuthenticationSchemes.Basic:
				authType = "Basic";
				break;
			case AuthenticationSchemes.Digest:
				authType = "Digest";
				break;
			case AuthenticationSchemes.Ntlm:
				authType = "Ntlm";
				break;
			case AuthenticationSchemes.Negotiate:
				authType = "Negotiate";
				break;
			}
			if (authType != null) {
				var cred = source.ClientCredentials;
				string user = cred != null ? cred.UserName.UserName : null;
				string pwd = cred != null ? cred.UserName.Password : null;
				if (String.IsNullOrEmpty (user))
					throw new InvalidOperationException (String.Format ("Use ClientCredentials to specify a user name for required HTTP {0} authentication.", authType));
				var nc = new NetworkCredential (user, pwd);
				web_request.Credentials = nc;
				// FIXME: it is said required in SL4, but it blocks full WCF.
				//web_request.UseDefaultCredentials = false;
			}
#endif

#if !NET_2_1 // FIXME: implement this to not depend on Timeout property
			web_request.Timeout = (int) timeout.TotalMilliseconds;
#endif

			// There is no SOAP Action/To header when AddressingVersion is None.
			if (message.Version.Envelope.Equals (EnvelopeVersion.Soap11) ||
			    message.Version.Addressing.Equals (AddressingVersion.None)) {
				if (message.Headers.Action != null) {
					web_request.Headers ["SOAPAction"] = String.Concat ("\"", message.Headers.Action, "\"");
					message.Headers.RemoveAll ("Action", message.Version.Addressing.Namespace);
				}
			}

			// apply HttpRequestMessageProperty if exists.
			bool suppressEntityBody = false;
#if !NET_2_1
			string pname = HttpRequestMessageProperty.Name;
			if (message.Properties.ContainsKey (pname)) {
				HttpRequestMessageProperty hp = (HttpRequestMessageProperty) message.Properties [pname];
				web_request.Headers.Clear ();
				web_request.Headers.Add (hp.Headers);
				web_request.Method = hp.Method;
				// FIXME: do we have to handle hp.QueryString ?
				if (hp.SuppressEntityBody)
					suppressEntityBody = true;
			}
#endif

			if (!suppressEntityBody && String.Compare (web_request.Method, "GET", StringComparison.OrdinalIgnoreCase) != 0) {
				MemoryStream buffer = new MemoryStream ();
				Encoder.WriteMessage (message, buffer);

				if (buffer.Length > int.MaxValue)
					throw new InvalidOperationException ("The argument message is too large.");

#if !NET_2_1
				web_request.ContentLength = (int) buffer.Length;
#endif

				web_request.BeginGetRequestStream (delegate (IAsyncResult r) {
					try {
						result.CompletedSynchronously &= r.CompletedSynchronously;
						using (Stream s = web_request.EndGetRequestStream (r))
							s.Write (buffer.GetBuffer (), 0, (int) buffer.Length);
						web_request.BeginGetResponse (GotResponse, result);
//.........这里部分代码省略.........
开发者ID:stabbylambda,项目名称:mono,代码行数:101,代码来源:HttpRequestChannel.cs

示例9: AttachBody

 internal void AttachBody(WebRequest request, Action<WebRequest> onRequestReady)
 {
     request.BeginGetRequestStream(new AsyncCallback(EndAttachBody),
         new object[] { request, onRequestReady });
 }
开发者ID:JANCARLO123,项目名称:google-apis,代码行数:5,代码来源:Request.cs

示例10: OpenWriteAsync

		public void OpenWriteAsync (Uri address, string method, object userToken)
		{
			if (address == null)
				throw new ArgumentNullException ("address");

			lock (locker) {
				SetBusy ();

				try {
					request = SetupRequest (address, method, new CallbackData (userToken));
					request.BeginGetRequestStream (new AsyncCallback (OpenWriteAsyncCallback), null);
				}
				catch (Exception e) {
					WebException wex = new WebException ("Could not start operation.", e);
					OnOpenWriteCompleted (
						new OpenWriteCompletedEventArgs (null, wex, false, userToken));
				}
			}
		}
开发者ID:nlhepler,项目名称:mono,代码行数:19,代码来源:WebClient_2_1.cs

示例11: GetRequestStream

 private Stream GetRequestStream(WebRequest request)
 {
     AutoResetEvent autoResetEvent = new AutoResetEvent(false);
     IAsyncResult asyncResult = request.BeginGetRequestStream(r => autoResetEvent.Set(), null);
     autoResetEvent.WaitOne();
     return request.EndGetRequestStream(asyncResult);
 }
开发者ID:jhskailand,项目名称:PortableWebClient,代码行数:7,代码来源:PortableWebClient.cs

示例12: UploadBits

        /// <devdoc>
        ///    <para>Takes a byte array or an open file stream and writes it to a server</para>
        /// </devdoc>

        private void UploadBits(WebRequest request, Stream readStream, byte[] buffer, byte [] header, byte [] footer, CompletionDelegate completionDelegate, AsyncOperation asyncOp) {
            if (request.RequestUri.Scheme == Uri.UriSchemeFile)
                header = footer = null;
            UploadBitsState state = new UploadBitsState(request, readStream, buffer, header, footer, completionDelegate, asyncOp, m_Progress, this);
            Stream writeStream;
            if (state.Async) {
                request.BeginGetRequestStream(new AsyncCallback(UploadBitsRequestCallback), state);
                return;
            } else {
                writeStream = request.GetRequestStream();
            }
            state.SetRequestStream(writeStream);
            while(!state.WriteBytes());
            state.Close();
        }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:19,代码来源:webclient.cs

示例13: SetPostData

 private static void SetPostData(object postdata, WebRequest request)
 {
     using (System.Threading.ManualResetEvent man = new System.Threading.ManualResetEvent(false))
     {
         request.Method = "POST";
         System.Runtime.Serialization.Json.DataContractJsonSerializer serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(postdata.GetType());
         using (var mem = new System.IO.MemoryStream())
         {
             serializer.WriteObject(mem, postdata);
             mem.Position = 0;
             request.ContentLength = mem.Length;
             request.BeginGetRequestStream((s) =>
             {
                 using (var postStream = request.EndGetRequestStream(s))
                 {
                     mem.CopyTo(postStream);
                 }
                 man.Set();
             }, null);
             man.WaitOne();
         }
     }
 }
开发者ID:jzi96,项目名称:JiraClient.SL,代码行数:23,代码来源:JiraRestWrapperService.cs

示例14: GetRequestStream

 internal Stream GetRequestStream(WebRequest request)
 {
     Stream stream = null;
     request.BeginGetRequestStream(a =>
     {
         stream = request.EndGetRequestStream(a);
         allDone.Set();
     }, null);
     allDone.WaitOne(TimeSpan.FromSeconds(30));
     return stream;
 }
开发者ID:mobeelizer,项目名称:wp7-sdk,代码行数:11,代码来源:MobeelizerConnectionService.cs

示例15: AttachBody

 internal void AttachBody(WebRequest request)
 {
     request.BeginGetRequestStream(EndAttachBody, request);
 }
开发者ID:nick0816,项目名称:LoggenCSG,代码行数:4,代码来源:Request.cs


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