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


C# HttpWebRequest.GetRequestStream方法代码示例

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


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

示例1: InsertSoapEnvelopeIntoWebRequest

 private static void InsertSoapEnvelopeIntoWebRequest(XmlDocument soapEnvelopeXml, HttpWebRequest webRequest)
 {
     using (Stream stream = webRequest.GetRequestStream())
     {
         soapEnvelopeXml.Save(stream);
     }
 }
开发者ID:neos1993,项目名称:-,代码行数:7,代码来源:SoapClientForPochtaRussia.cs

示例2: SendRequest

        public void SendRequest(HttpWebRequest request)
        {
            int index = 0, size = 0;
            byte[][] data = new byte[Count * 2][];
            foreach (string key in AllKeys)
            {
                data[index] = HttpUtility.UrlEncodeToBytes(key);
                size += data[index++].Length;

                data[index] = HttpUtility.UrlEncodeToBytes(this[key]);
                size += data[index++].Length;
            }

            request.ContentType = "application/x-www-form-urlencoded";
            request.ContentLength = size + Count * 2 - 1;

            using (Stream requestStream = request.GetRequestStream())
            {
                for (int i = 0; i < data.Length; i++)
                {
                    byte[] buff = data[i];
                    requestStream.Write(buff, 0, buff.Length);
                    if (i < data.Length - 1)
                        requestStream.WriteByte(SeparatorBytes[i % 2]);
                }
            }
        }
开发者ID:kidaa,项目名称:Pulse,代码行数:27,代码来源:HttpRequestParams.cs

示例3: RequestAndRespond

        private Result RequestAndRespond(HttpWebRequest request, string content)
        {
            HttpStatusCode statusCode = HttpStatusCode.NotFound;

            try
            {
                var contentBytes = Encoding.UTF8.GetBytes(content);
                request.ContentLength = contentBytes.Length;
                using (var stream = request.GetRequestStream())
                {
                    stream.Write(contentBytes, 0, contentBytes.Length);
                }

                using (var response = request.GetResponse() as HttpWebResponse)
                {
                    statusCode = HttpClient.GetStatusCode(response);
                }
            }
            catch (WebException webException)
            {
                var response = webException.Response as HttpWebResponse;
                statusCode = HttpClient.GetStatusCode(response);
            }

            return HttpStatusCodeExtensions.ToResult(statusCode);
        }
开发者ID:B2MSolutions,项目名称:reyna.net,代码行数:26,代码来源:HttpClient.cs

示例4: AddXmlToRequest

        /// <summary>
        /// Adds the XML to web request. The XML is the standard
        /// XML used by RPC-XML requests.
        /// </summary>
        private static void AddXmlToRequest(Uri sourceUrl, Uri targetUrl, HttpWebRequest webreqPing)
        {
            Stream stream = (Stream)webreqPing.GetRequestStream();
              using (XmlTextWriter writer = new XmlTextWriter(stream, Encoding.ASCII))
              {
            writer.WriteStartDocument(true);
            writer.WriteStartElement("methodCall");
            writer.WriteElementString("methodName", "pingback.ping");
            writer.WriteStartElement("params");

            writer.WriteStartElement("param");
            writer.WriteStartElement("value");
            writer.WriteElementString("string", sourceUrl.ToString());
            writer.WriteEndElement();
            writer.WriteEndElement();

            writer.WriteStartElement("param");
            writer.WriteStartElement("value");
            writer.WriteElementString("string", targetUrl.ToString());
            writer.WriteEndElement();
            writer.WriteEndElement();

            writer.WriteEndElement();
            writer.WriteEndElement();
              }
        }
开发者ID:chandru9279,项目名称:StarBase,代码行数:30,代码来源:Pingback.cs

示例5: EjecutarAccion

        public string EjecutarAccion(string url, string metodo, object modelo = null)
        {
            request = WebRequest.Create(url) as HttpWebRequest;
            request.Timeout = 10 * 1000;
            request.Method = metodo;
            request.ContentType = "application/json; charset=utf-8";

            string credentials = Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(usuario + ":" + clave));
            request.Headers.Add("Authorization", "Basic " + credentials);

            if (modelo != null)
            {
                var postString = new JavaScriptSerializer().Serialize(modelo);
                byte[] data = UTF8Encoding.UTF8.GetBytes(postString);
                request.ContentLength = data.Length;
                Stream postStream = request.GetRequestStream();
                postStream.Write(data, 0, data.Length);
            }
            HttpWebResponse response = request.GetResponse() as HttpWebResponse;
            if (response.StatusCode != HttpStatusCode.NoContent)
            {
                StreamReader reader = new StreamReader(response.GetResponseStream());
                return reader.ReadToEnd();
            }

            return "";
        }
开发者ID:erick03,项目名称:clienteWeb,代码行数:27,代码来源:Enlace.cs

示例6: Login

        public Login(string Username, string Password)
        {
            string url = string.Format("http://www.myfitnesspal.com/account/login");
            request = (HttpWebRequest)WebRequest.Create(url);

            request.AllowAutoRedirect = false;
            request.CookieContainer = new CookieContainer();

            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            string NewValue = string.Format("username={0}&password={1}&remember_me=1",Username,Password);
            request.ContentLength = NewValue.Length;
            // Write the request
            StreamWriter stOut = new StreamWriter(request.GetRequestStream(), System.Text.Encoding.ASCII);
            stOut.Write(NewValue);
            stOut.Close();
            // Do the request to get the response
            response = (HttpWebResponse)request.GetResponse();
            StreamReader stIn = new StreamReader(response.GetResponseStream());

            string strResponse = stIn.ReadToEnd();
            stIn.Close();

            cookies = request.CookieContainer;
            response.Close();
        }
开发者ID:PCurd,项目名称:MyFitnessPalApp,代码行数:26,代码来源:Login.cs

示例7: WriteMultipartBodyToRequest

        private static void WriteMultipartBodyToRequest(HttpWebRequest request, string body)
        {
            string[] multiparts = Regex.Split(body, @"<!>");
            byte[] bytes;
            using (MemoryStream ms = new MemoryStream())
            {
                foreach (string part in multiparts)
                {
                    if (File.Exists(part))
                    {
                        bytes = File.ReadAllBytes(part);
                    }
                    else
                    {
                        bytes = System.Text.Encoding.UTF8.GetBytes(part.Replace("\r\n", "\n").Replace("\r", "\n").Replace("\n", "\r\n"));
                    }

                    ms.Write(bytes, 0, bytes.Length);
                }

                request.ContentLength = ms.Length;
                using (Stream stream = request.GetRequestStream())
                {
                    ms.WriteTo(stream);
                }
            }
        }
开发者ID:poolsar,项目名称:LotCreator,代码行数:27,代码来源:UploadImage24Au.cs

示例8: UploadString

        public static string UploadString(HttpWebRequest request, string Data, CookieCollection Cookies)
        {
            string ret = "";
            request.CookieContainer = new CookieContainer();
            foreach (Cookie cookie in Cookies)
                request.CookieContainer.Add(cookie);

            //request.Headers = Headers;
            HttpWebResponse res;
            request.Method = "POST";
            
            //request.ContentLength = Data.Length;
            using (Stream s = request.GetRequestStream())
            {
                using (StreamWriter sw = new StreamWriter(s))
                {
                    sw.Write(Data);
                    //s.Close();
                    sw.Close();
                }
            }
            ret = GetString(request, out res);

            return ret;        
        }
开发者ID:Hagser,项目名称:csharp,代码行数:25,代码来源:MyWebClient.cs

示例9: GetCookie

        protected CookieContainer GetCookie(HttpWebRequest request, CookieContainer cc, byte[] content)
        {
            if (cc != null)
            {
                request.CookieContainer = cc;
            }
            else
            {
                request.CookieContainer = new CookieContainer();
                cc = request.CookieContainer;
            }

            try
            {
                Stream stream = request.GetRequestStream();
                stream.Write(content, 0, content.Length);
                stream.Close();
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                response.Cookies = request.CookieContainer.GetCookies(request.RequestUri);
                //CookieCollection cook = response.Cookies;
                string CookiesString = request.CookieContainer.GetCookieHeader(request.RequestUri);
                // TODO  save cookiesstring to xml file
            }
            catch (WebException wex)
            {
                // TODO Log
            }
            catch (Exception ex)
            {
                // TODO log
            }
            return cc;
        }
开发者ID:helloxyz,项目名称:PostingRobot,代码行数:33,代码来源:ClientSession.cs

示例10: GetResponse

 public static string GetResponse(HttpWebRequest req, byte[] bytes)
 {
     try
     {
         using (Stream stream = req.GetRequestStream())
         {
             stream.Write(bytes, 0, bytes.Length);
         }
         using (HttpWebResponse res = req.GetResponse() as HttpWebResponse)
         {
             if (res.StatusCode == HttpStatusCode.OK)
             {
                 using (Stream stream = res.GetResponseStream())
                 {
                     using (StreamReader reader = new StreamReader(stream))
                     {
                         return reader.ReadToEnd();
                     }
                 }
             }
             else
             {
                 string message = String.Format("POST failed. Received HTTP {0}", res.StatusCode);
                 throw new ApplicationException(message);
             }
         }
     }
     catch(WebException e)
     {
         throw new RestHostMissingException(e);
     }
 }
开发者ID:shentianyi,项目名称:ifscmClient,代码行数:32,代码来源:RestRequest.cs

示例11: DoRequest

        private void DoRequest(string url, string postData) {
            _request = (HttpWebRequest)WebRequest.Create("http://localhost" + url);
            _request.CookieContainer = _cookieContainer;
            if (postData != null) {
                _request.Method = "POST";
                _request.ContentType = "application/x-www-form-urlencoded";
                using (var stream = _request.GetRequestStream()) {
                    using (var writer = new StreamWriter(stream)) {
                        writer.Write(postData);
                    }
                }
            }
            try {
                _response = (HttpWebResponse)_request.GetResponse();
            }
            catch (WebException ex) {
                _response = (HttpWebResponse)ex.Response;
            }

            using (var stream = _response.GetResponseStream()) {
                using (var reader = new StreamReader(stream)) {
                    _text = reader.ReadToEnd();
                }
            }
        }
开发者ID:anycall,项目名称:Orchard,代码行数:25,代码来源:HttpClient.cs

示例12: HeartBeatHandler

        void HeartBeatHandler() {
            while( true ) {
                try {
                    request = (HttpWebRequest)WebRequest.Create( URL );
                    request.Method = "POST";
                    request.Timeout = 15000; // 15s timeout
                    request.ContentType = "application/x-www-form-urlencoded";
                    request.CachePolicy = new System.Net.Cache.RequestCachePolicy( System.Net.Cache.RequestCacheLevel.NoCacheNoStore );
                    byte[] formData = Encoding.ASCII.GetBytes( staticData + "&users=" + world.GetPlayerCount() );
                    request.ContentLength = formData.Length;

                    using( Stream requestStream = request.GetRequestStream() ) {
                        requestStream.Write( formData, 0, formData.Length );
                        requestStream.Flush();
                    }

                    if( !hasReportedServerURL ) {
                        using( WebResponse response = request.GetResponse() ) {
                            using( StreamReader responseReader = new StreamReader( response.GetResponseStream() ) ) {
                                world.config.ServerURL = responseReader.ReadToEnd().Trim();
                            }
                        }
                        request.Abort();
                        hash = world.config.ServerURL.Substring( world.config.ServerURL.LastIndexOf( '=' ) + 1 );
                        world.FireURLChange( world.config.ServerURL );
                        hasReportedServerURL = true;
                    }

                } catch( Exception ex ) {
                    world.log.Log( "HeartBeat: {0}", LogType.Error, ex.Message );
                }

                try {
                    request = (HttpWebRequest)WebRequest.Create( fListURL );
                    request.Method = "POST";
                    request.Timeout = 15000; // 15s timeout
                    request.ContentType = "application/x-www-form-urlencoded";
                    request.CachePolicy = new System.Net.Cache.RequestCachePolicy( System.Net.Cache.RequestCacheLevel.NoCacheNoStore );
                    string requestString = staticData +
                                            "&users=" + world.GetPlayerCount() +
                                            "&hash=" + hash +
                                            "&motd=" + Server.UrlEncode( world.config.GetString( "MOTD" ) ) +
                                            "&server=fcraft" +
                                            "&players=" + world.GetPlayerListString();
                    byte[] formData = Encoding.ASCII.GetBytes( requestString );
                    request.ContentLength = formData.Length;

                    using( Stream requestStream = request.GetRequestStream() ) {
                        requestStream.Write( formData, 0, formData.Length );
                        requestStream.Flush();
                    }
                    request.Abort();
                } catch( Exception ex ) {
                    world.log.Log( "HeartBeat: Error reporting to fList: {0}", LogType.Error, ex.Message );
                }

                Thread.Sleep( Config.HeartBeatDelay );
            }
        }
开发者ID:fragmer,项目名称:fCraft,代码行数:59,代码来源:HeartBeat.cs

示例13: handleValidResponse

 private HttpWebResponse handleValidResponse(HttpWebRequest request, byte[] bytes)
 {
     using (var newStream = request.GetRequestStream()) {
         newStream.Write(bytes, 0, bytes.Length);
         newStream.Close();
     }
     return (HttpWebResponse) request.GetResponse();
 }
开发者ID:rcsir,项目名称:RuNetImporter,代码行数:8,代码来源:PostRequests.cs

示例14: CopyFile

 public static void CopyFile(HttpWebRequest request, string file)
 {
     FileStream fileStream = File.OpenRead(file);
     Stream rs = request.GetRequestStream();
     Utils.CopyNBit (rs, fileStream, fileStream.Length);
     fileStream.Close ();
     rs.Close ();
 }
开发者ID:hsiun,项目名称:yoyo,代码行数:8,代码来源:Utils.cs

示例15: InputPostData

 void InputPostData(string postData, HttpWebRequest req)
 {
     byte[] data = Encoding.ASCII.GetBytes(postData);
       req.ContentLength = data.Length;
       using (var input = req.GetRequestStream()) {
     input.Write(data, 0, data.Length);
       }
 }
开发者ID:defensio,项目名称:defensio-dotnet,代码行数:8,代码来源:RestClient.cs


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