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


C# HttpWebRequest.EndGetRequestStream方法代码示例

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


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

示例1: GetRequestStreamAsync

        public Task<Stream> GetRequestStreamAsync(HttpWebRequest request)
        {
            var tcs = new TaskCompletionSource<Stream>();

            try
            {
                request.BeginGetRequestStream(iar =>
                {
                    try
                    {
                        var response = request.EndGetRequestStream(iar);
                        tcs.SetResult(response);
                    }
                    catch (Exception exc)
                    {
                        tcs.SetException(exc);
                    }
                }, null);
            }
            catch (Exception exc)
            {
                tcs.SetException(exc);
            }

            return tcs.Task;
        }
开发者ID:daltekkie,项目名称:Emby.ApiClient,代码行数:26,代码来源:PortableHttpWebRequestFactory.cs

示例2: GetRequestStreamAsynch

 private Stream GetRequestStreamAsynch(HttpWebRequest request)
 {
     return AsynchHelper.WaitForAsynchResponse(
         c => request.BeginGetRequestStream(c, null),
         (r, s) => request.EndGetRequestStream(r)
     );
 }
开发者ID:sergioazevedo,项目名称:restfulie-net,代码行数:7,代码来源:DefaultRequestDispatcher.cs

示例3: POST

 protected void POST(string URL, string post_message)
 {
     POST_REQUEST = (HttpWebRequest)HttpWebRequest.Create(URL);
     POST_REQUEST.Method = "POST";
     POST_REQUEST.ContentType = "application/x-www-form-urlencoded";
     POST_REQUEST.BeginGetRequestStream(result =>
     {
         Stream post_stream = POST_REQUEST.EndGetRequestStream(result);
         byte[] ba = Encoding.UTF8.GetBytes(post_message);
         post_stream.Write(ba, 0, ba.Length);
         post_stream.Close();
         POST_REQUEST.BeginGetResponse(new AsyncCallback(POST_Method_CallBack),POST_REQUEST);
     }, POST_REQUEST);
 }
开发者ID:ahmeda8,项目名称:audio-youtube-wp7,代码行数:14,代码来源:WebMethods.cs

示例4: GetRequestStream

        void GetRequestStream(HttpWebRequest request, Action<HttpResponse> callback)
        {
            request.BeginGetRequestStream(ar =>
                {
                    using (var stream = request.EndGetRequestStream(ar))
                    {
                        if (HasFiles)
                        {
                            WriteMultipartFormData(stream);
                        }
                        else // This is when we have a RequestBody
                        {
                            stream.Write(Encoding.UTF8.GetBytes(RequestBody), 0, RequestBody.Length);
                        }
                    }

                    GetHttpResponse(request, callback);
                }, null);
        }
开发者ID:koenmetsu,项目名称:XBMC.Remote,代码行数:19,代码来源:Http.cs

示例5: Start

            /// <summary>
            /// Used by the worker thread to start the request
            /// </summary>
            public void Start()
            {
                try
                {
                    // Create the request
                    request = (HttpWebRequest)System.Net.WebRequest.Create(URL);
                    request.Method = Method;
                    request.Credentials = CredentialCache.DefaultCredentials;
                    request.Proxy = null;
                    request.KeepAlive = false;
                    request.Timeout = (int)Math.Round((Timeout == 0f ? WebRequests.Timeout : Timeout) * 1000f);
                    request.ServicePoint.MaxIdleTime = request.Timeout;
                    request.ServicePoint.Expect100Continue = ServicePointManager.Expect100Continue;
                    request.ServicePoint.ConnectionLimit = ServicePointManager.DefaultConnectionLimit;

                    // Optional request body for post requests
                    var data = new byte[0];
                    if (Body != null)
                    {
                        data = Encoding.UTF8.GetBytes(Body);
                        request.ContentLength = data.Length;
                        request.ContentType = "application/x-www-form-urlencoded";
                    }

                    if (RequestHeaders != null) request.SetRawHeaders(RequestHeaders);

                    // Perform DNS lookup and connect (blocking)
                    if (data.Length > 0)
                    {
                        request.BeginGetRequestStream(result =>
                        {
                            if (request == null) return;
                            try
                            {
                                // Write request body
                                using (var stream = request.EndGetRequestStream(result))
                                    stream.Write(data, 0, data.Length);
                            }
                            catch (Exception ex)
                            {
                                ResponseText = ex.Message.Trim('\r', '\n', ' ');
                                if (request != null) request.Abort();
                                OnComplete();
                                return;
                            }
                            WaitForResponse();
                        }, null);
                    }
                    else
                    {
                        WaitForResponse();
                    }
                }
                catch (Exception ex)
                {
                    ResponseText = ex.Message.Trim('\r', '\n', ' ');
                    Interface.Oxide.LogException(string.Format("Web request produced exception (Url: {0})", URL), ex);
                    if (request != null) request.Abort();
                    OnComplete();
                }
            }
开发者ID:CypressCube,项目名称:Oxide,代码行数:64,代码来源:WebRequests.cs

示例6: ProcessRequestThen

        protected virtual void ProcessRequestThen(
            MvxRestRequest restRequest,
            HttpWebRequest httpRequest,
            Action continueAction,
            Action<Exception> errorAction)
        {
            httpRequest.BeginGetRequestStream(result =>
                                              TryCatch(() =>
                                                  {
                                                      using (var stream = httpRequest.EndGetRequestStream(result))
                                                      {
                                                          restRequest.ProcessRequestStream(stream);
                                                          stream.Flush();
                                                      }

                                                      continueAction?.Invoke();
                                                  }, errorAction)
                                              , null);
        }
开发者ID:andyci,项目名称:MvvmCross-Plugins,代码行数:19,代码来源:MvxRestClient.cs

示例7: HandleGetRequestStream

		static void HandleGetRequestStream (IAsyncResult res, HttpWebRequest request, string body)
		{
			try {
				Stream s = request.EndGetRequestStream (res);
				using (var sw = new StreamWriter (s)) {
					sw.Write (body);
				}
				WebResponse resp = request.GetResponse ();
				s = resp.GetResponseStream ();
				string result;
				using (var sr = new StreamReader (s))
					result = sr.ReadToEnd ();
				if (result != "OK")
					throw new Exception (result);
			}
			catch (Exception ex) {
				LoggingService.LogError ("Feedback submission failed", ex);
				lock (sendingLock) {
					sending = false;
				}
				return;
			}
			LoggingService.LogInfo ("Feedback successfully sent");
			lock (sendingLock) {
				XmlDocument doc = LoadFeedbackDoc ();
				if (doc.DocumentElement != null) {
					var first = doc.DocumentElement.FirstChild;
					doc.DocumentElement.RemoveChild (first);
					doc.Save (FeedbackFile);
					
					XmlElement fe = doc.DocumentElement.FirstChild as XmlElement;
					if (fe != null)
						InternalSendFeedback (fe);
					else
						sending = false;
				}
				else
					sending = false;
			}
		}
开发者ID:Poiros,项目名称:monodevelop,代码行数:40,代码来源:FeedbackService.cs

示例8: sendMessageAsync

        private void sendMessageAsync(IAsyncResult asynchronousResult, HttpWebRequest request, byte[] data, String message)
        {
            try{

                // End the operation
                Stream postStream = request.EndGetRequestStream(asynchronousResult);

                postStream.Write(data, 0, data.Length);
                postStream.Close();

                // Start the asynchronous operation to get the response
                request.BeginGetResponse(result => {
                    receiveMessageAsync(result, request, message, postAsyncSendFailResult);
                },null);
            } catch ( Exception e) {
                log.errorCause("error while  sending command " + e.Message, e);
                postAsyncSendFailResult();
            }
        }
开发者ID:technerdlove,项目名称:SnowBallZ,代码行数:19,代码来源:NUnityNetEditor.cs

示例9: DoPost

        private Response DoPost(HttpWebRequest req, string postData)
        {
            Response res = null;
            AutoResetEvent signal = new AutoResetEvent(false);
            try
            {
                req.BeginGetRequestStream(reqState =>
                {
                    try
                    {
                        Stream reqStream = req.EndGetRequestStream(reqState);
                        if (postData != null)
                        {
                            Encoding enc = new System.Text.UTF8Encoding();
                            reqStream.Write(enc.GetBytes(postData), 0, postData.Length);
                        }
                        reqStream.Close();
                        res = DoRequest(req);
                    }
                    catch (Exception ex)
                    {
                        res = new Response(-1, ex.ToString(), null);
                    }
                    finally
                    {
                        signal.Set();
                    }
                }, null);
            }
            catch (Exception ex)
            {
                res = new Response(-1, ex.ToString(), null);
                signal.Set();
            }

            signal.WaitOne();
            return res;
        }
开发者ID:hastoukopsaro,项目名称:tapstream-sdk,代码行数:38,代码来源:PlatformImpl.cs

示例10: PostWebRequest

        private static void PostWebRequest(IAsyncResult result,
            HttpWebRequest request,
            string filename)
        {
            Stream postStream = request.EndGetRequestStream(result);
            String post;
            using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                IsolatedStorageFileStream isoFileStream = myIsolatedStorage.OpenFile(DIR + "//" + filename, FileMode.Open);
                using (StreamReader reader = new StreamReader(isoFileStream))
                {
                    post = reader.ReadToEnd();
                }
            }
            byte[] postBytes = Encoding.UTF8.GetBytes(post);
            postStream.Write(postBytes, 0, postBytes.Length);
            postStream.Close();

            request.BeginGetResponse(res =>
            {
                GetResponseCallback(res, request, filename);
            }, null);
        }
开发者ID:K2DaC,项目名称:ErrBitWP,代码行数:23,代码来源:ErrBitNotify.cs

示例11: GetRequestStream

        /// <summary>
        /// Gets the request stream in synchronous way.
        /// </summary>
        private Stream GetRequestStream(HttpWebRequest request)
        {
#if WINDOWS_PHONE || SILVERLIGHT
            _requestStreamReceived = false;
            IAsyncResult asyncResult;

            try
            {
                asyncResult = request.BeginGetRequestStream(AsyncPhoneWebRequestStreamCallback, request);
            }
            catch (SecurityException)
            {
                return null;
            }
            catch (WebException)
            {
                return null;
            }

            // HACK: take a look on comment of GetResponse() method...
            while (!_requestStreamReceived)
            {
                Thread.Sleep(50);
            }

            return request.EndGetRequestStream(asyncResult);
#elif WINDOWS_STORE
            throw new NotSupportedException("Synchronous versions are not supported");
#else
            return request.GetRequestStream();
#endif
        }
开发者ID:phofman,项目名称:codetitans-libs,代码行数:35,代码来源:HttpDataSource.cs

示例12: WriteRequestData

        private bool WriteRequestData(HttpWebRequest request, IAsyncResult asyncResult, byte[] data, int dataLength)
        {
            Stream requestStream = null;

            try
            {
                requestStream = asyncResult != null ? request.EndGetRequestStream(asyncResult) : GetRequestStream(request);

                if (requestStream == null)
                    return true;

                WriteRequestData(requestStream, data, dataLength);
            }
            catch (SecurityException ex)
            {
                Event.Invoke(DataReceiveFailed, this, new HttpDataSourceEventArgs(this, HttpStatusCode.BadRequest, ex.Message));
                TryCompleteRequest(request);

                return true;
            }
            catch (WebException ex)
            {
                if (ex.Status != WebExceptionStatus.RequestCanceled)
                    Event.Invoke(DataReceiveFailed, this, new HttpDataSourceEventArgs(this, GetHttpStatusCode(ex.Status), ex.Message));
                TryCompleteRequest(request);

                return true;
            }
            finally
            {
                if (requestStream != null)
                {
#if WINDOWS_STORE
                    requestStream.Dispose();
#else
                    requestStream.Close();
#endif
                }
            }

            return false;
        }
开发者ID:phofman,项目名称:codetitans-libs,代码行数:42,代码来源:HttpDataSource.cs

示例13: GetRequestStream

        private Stream GetRequestStream(HttpWebRequest req)
        {
            var asyncResult = req.BeginGetRequestStream(null, null);
            var hasNotTimedOut = asyncResult.AsyncWaitHandle.WaitOne(Timeout);
            if (!hasNotTimedOut)
            {
                // TODO: Not really an issue with the cache server.
                throw new CacheServerException("Could not get request stream");
            }

            return req.EndGetRequestStream(asyncResult);
        }
开发者ID:jimmcslim,项目名称:Ehcache.Net,代码行数:12,代码来源:EhcacheServerRequest.cs

示例14: LoadBodyAndSendAsync

 private void LoadBodyAndSendAsync(HttpWebRequest request)
 {
     if (_bodyReader != null || _bodyString != null) {
         request.BeginGetRequestStream(asyncRequestStreamResult => {
             WriteBody(request.EndGetRequestStream(asyncRequestStreamResult));
             SendAsyncRequest(request);
         }, null);
     }
     else {
         SendAsyncRequest(request);
     }
 }
开发者ID:knifhen,项目名称:buttercup-swedish,代码行数:12,代码来源:Request.cs

示例15: WriteRequestBody

        private void WriteRequestBody(HttpWebRequest webRequest)
        {
            if (this.HasBody || this.HasFiles || this.AlwaysMultipartFormData)
            {
            #if !WINDOWS_PHONE
            #if (NETCORE50 || NETSTANDARD1_5 || NETSTANDARD1_6)
            #else
                webRequest.ContentLength = this.CalculateContentLength();
            #endif
            #endif
            }

            #if (NETCORE50 || NETSTANDARD1_5 || NETSTANDARD1_6)
            var asyncResult = webRequest.BeginGetRequestStream(null, null);
            using (Stream requestStream = webRequest.EndGetRequestStream(asyncResult))
            #else
            using (Stream requestStream = webRequest.GetRequestStream())
            #endif
            {
                if (this.HasFiles || this.AlwaysMultipartFormData)
                {
                    this.WriteMultipartFormData(requestStream);
                }
                else if (this.RequestBodyBytes != null)
                {
                    requestStream.Write(this.RequestBodyBytes, 0, this.RequestBodyBytes.Length);
                }
                else if (this.RequestBody != null)
                {
                    this.WriteStringTo(requestStream, this.RequestBody);
                }
            }
        }
开发者ID:CL0SeY,项目名称:RestSharp,代码行数:33,代码来源:Http.Sync.cs


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