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


C# HttpWebRequest.GetRequestStream方法代码示例

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


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

示例1: AddRequestXml

    private void AddRequestXml(string url, HttpWebRequest req)
    {
        Stream stream = (Stream)req.GetRequestStream();
        using (XmlTextWriter writer = new XmlTextWriter(stream, Encoding.UTF8))
        {
            writer.WriteStartDocument(true);
            writer.WriteStartElement("methodCall");
            writer.WriteElementString("methodName", "pingback.ping");
            writer.WriteStartElement("params");

            writer.WriteStartElement("param");
            writer.WriteStartElement("value");
            writer.WriteElementString("string", Blogsa.Url);
            writer.WriteEndElement();
            writer.WriteEndElement();

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

            writer.WriteEndElement();
            writer.WriteEndElement();
        }
    }
开发者ID:Blogsa,项目名称:blogsa,代码行数:26,代码来源:SendPings.cs

示例2: createDataStream

 public Stream createDataStream(Dictionary<string,string> body ,HttpWebRequest request)
 {
     string theBody = "";
     foreach(KeyValuePair<string,string> bodyPart in body){
         theBody = theBody + bodyPart.Key + "=" + bodyPart.Value + "&";
     }
     byte[] byteArray = Encoding.UTF8.GetBytes(theBody);
     request.ContentLength = byteArray.Length;
     Stream dataStream = request.GetRequestStream();
     dataStream.Write(byteArray, 0,byteArray.Length);
     dataStream.Close ();
     return dataStream;
 }
开发者ID:Nersle,项目名称:Unity,代码行数:13,代码来源:Postman.cs

示例3: FillRequestWithContent

 public static void FillRequestWithContent(HttpWebRequest request, string contentPath)
 {
     using (BinaryReader reader = new BinaryReader(File.OpenRead(contentPath)))
     {
         request.ContentLength = reader.BaseStream.Length;
         using (Stream stream = request.GetRequestStream())
         {
             byte[] buffer = new byte[reader.BaseStream.Length];
             while (true)
             {
                 int bytesRead = reader.Read(buffer, 0, buffer.Length);
                 if (bytesRead == 0)
                 {
                     break;
                 }
                 stream.Write(buffer, 0, bytesRead);
             }
         }
     }
 }
开发者ID:rgg1992,项目名称:Test,代码行数:20,代码来源:AbbyyReader.cs

示例4: InsertSoapEnvelopeIntoWebRequest

 /// <summary>
 /// Insert soap envelope into web request
 /// </summary>
 /// <returns></returns>
 private static void InsertSoapEnvelopeIntoWebRequest(XmlDocument soapEnvelopeXml, HttpWebRequest webRequest)
 {
     using (Stream stream = webRequest.GetRequestStream())
     {
         soapEnvelopeXml.Save(stream);
     }
 }
开发者ID:Qwatcha,项目名称:payu-mea-code-examples-rpp-dotnet,代码行数:11,代码来源:Default.aspx.cs

示例5: StartProcess

    public void StartProcess()
    {
        try
        {
            byte[] byteData = null;
            request = (HttpWebRequest)WebRequest.Create(this.url);
            request.CookieContainer = cc;
            request.UserAgent = "Mozilla/4.0 (Compatible; Windows NT 5.1; MSIE 6.0) " +
                "(compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
            request.Timeout = requestTimeout;
            if (this.sendData != null)
            {
                ASCIIEncoding encoding = new ASCIIEncoding();
                byteData = System.Text.Encoding.UTF8.GetBytes(this.sendData);//encoding.GetBytes(this.sendData);
                request.Method = "POST";
                request.ContentLength = byteData.Length;
                request.ContentType = "application/x-www-form-urlencoded";

                Stream s = request.GetRequestStream();
                s.Write(byteData, 0, byteData.Length);
                s.Close();
            }

            HttpWebResponse response = null;
            try
            {
                response = (HttpWebResponse)request.GetResponse();
                receiveData = response.GetResponseStream();
            }
            catch (WebException we)
            {
                receiveData = we.Response.GetResponseStream();
            }

            //System.Windows.Forms.MessageBox.Show(response.Headers.Get("Set-Cookie"));
        }
        catch (Exception exc)
        {
            System.Windows.Forms.MessageBox.Show("Səhv baş verdi!\nİnternet bağlantınızın açıq olmağını dəqiqləşdirin.","Xəbərdarlıq",System.Windows.Forms.MessageBoxButtons.OK,System.Windows.Forms.MessageBoxIcon.Warning);
        }
    }
开发者ID:ElvinEfendi,项目名称:AutoCongratulator-Client-Program,代码行数:41,代码来源:GetResponseByRequest.cs

示例6: Submit

	public HttpWebResponse Submit (Uri uri, FSpot.ProgressItem progress_item) 
	{
		this.Progress = progress_item;
		Request = (HttpWebRequest) WebRequest.Create (uri);
		CookieCollection cookie_collection = Cookies.GetCookies (uri);

		if (uri.UserInfo != null && uri.UserInfo != String.Empty) {
			NetworkCredential cred = new NetworkCredential ();
			cred.GetCredential (uri, "basic");
			CredentialCache credcache = new CredentialCache();
			credcache.Add(uri, "basic", cred);
			
			Request.PreAuthenticate = true;
			Request.Credentials = credcache;	
		}

		Request.ServicePoint.Expect100Continue = expect_continue;

		Request.CookieContainer = new CookieContainer ();
		foreach (Cookie c in cookie_collection) {
			if (SuppressCookiePath) 
				Request.CookieContainer.Add (new Cookie (c.Name, c.Value));
			else
				Request.CookieContainer.Add (c);
		}

		Request.Method = "POST";
		Request.Headers["Accept-Charset"] = "utf-8;";
		
		//Request.UserAgent = "F-Spot Gallery Remote Client";
		Request.UserAgent = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7) Gecko/20040626 Firefox/0.9.1";

		Request.Proxy = WebProxy.GetDefaultProxy ();

		if (multipart) {
			GenerateBoundary ();
			Request.ContentType = "multipart/form-data; boundary=" + boundary;
			Request.Timeout = Request.Timeout * 3;

			long length = 0;
			for (int i = 0; i < Items.Count; i++) {
				FormItem item = (FormItem)Items[i];
				
				length += MultipartLength (item);
			}
			length += end_boundary.Length + 2;
			
			//Request.Headers["My-Content-Length"] = length.ToString ();
			if (Buffer == false) {
				Request.ContentLength = length;	
				Request.AllowWriteStreamBuffering = false;
			}
		} else {
			Request.ContentType = "application/x-www-form-urlencoded";
		}
		
		stream_writer = new StreamWriter (Request.GetRequestStream ());
		
		first_item = true;
		for (int i = 0; i < Items.Count; i++) {
			FormItem item = (FormItem)Items[i];
			
			Write (item);
		}
		
		if (multipart)
			stream_writer.Write (end_boundary + "\r\n");
		
		stream_writer.Flush ();
		stream_writer.Close ();

		HttpWebResponse response; 

		try {
			response = (HttpWebResponse) Request.GetResponse ();
			
			//Console.WriteLine ("found {0} cookies", response.Cookies.Count);
			
			foreach (Cookie c in response.Cookies) {
				Cookies.Add (c);
			}
		} catch (WebException e) {
			if (e.Status == WebExceptionStatus.ProtocolError 
			    && ((HttpWebResponse)e.Response).StatusCode == HttpStatusCode.ExpectationFailed && expect_continue) {
				e.Response.Close ();
				expect_continue = false;
				return Submit (uri, progress_item);
			}
			
			throw new WebException (Mono.Unix.Catalog.GetString ("Unhandled exception"), e);
		}

		return response;
	}
开发者ID:AminBonyadUni,项目名称:facedetect-f-spot,代码行数:94,代码来源:FormClient.cs

示例7: HTTPPost

        public HTTPPost(Uri Url, Dictionary<string, string> Parameters)
        {
            StringBuilder respBody = new StringBuilder();

            request = (HttpWebRequest)HttpWebRequest.Create(Url);
            request.UserAgent = "Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1C10 Safari/419.3";
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            string content = "?";
            foreach (string k in Parameters.Keys)
            {
                content += k + "=" + Parameters[k] + "&";
            }
            content = content.TrimEnd(new char[] { '&' });
            ASCIIEncoding encoding = new ASCIIEncoding();
            byte[] byte1 = encoding.GetBytes(content);
            request.ContentLength = byte1.Length;
            byte[] buf = new byte[8192];
            using (Stream rs = request.GetRequestStream())
            {
                rs.Write(byte1, 0, byte1.Length);
                rs.Close();

                response = (HttpWebResponse)request.GetResponse();
                Stream respStream = response.GetResponseStream();

                int count = 0;
                do
                {
                    count = respStream.Read(buf, 0, buf.Length);
                    if (count != 0)
                        respBody.Append(Encoding.ASCII.GetString(buf, 0, count));
                }
                while (count > 0);

                respStream.Close();
                ResponseBody = respBody.ToString();
                EscapedBody = GetEscapedBody();
                StatusCode = GetStatusLine();
                Headers = GetHeaders();

                response.Close();
            }
        }
开发者ID:ranjancse26,项目名称:FourSquareAnalytics,代码行数:44,代码来源:NetSquare.cs

示例8: AddPostDataTo

 /// <summary>
 /// Assembles the Post data and attaches to the request object
 /// </summary>
 private void AddPostDataTo(HttpWebRequest request)
 {
     string payload = FormElements.AssemblePostPayload();
     byte[] buff = Encoding.UTF8.GetBytes(payload.ToCharArray());
     request.ContentLength = buff.Length;
     request.ContentType = "application/x-www-form-urlencoded";
     System.IO.Stream reqStream = request.GetRequestStream();
     reqStream.Write(buff, 0, buff.Length);
 }
开发者ID:Transcanada-TRPS,项目名称:TBOT,代码行数:12,代码来源:BrowserSession.cs

示例9: SendEncodedString

    private void SendEncodedString(string encondedValue, string guid, string algorithmName)
    {
        HttpWebRequest request;
        HttpWebResponse response;
        PostRequestEnconded requestContent = new PostRequestEnconded();
        string serializedJsonContent;
        byte[] contentBytes;

        request =  WebRequest.Create(url + "values/" + guid + "/" + algorithmName) as HttpWebRequest;
        request.Method = "POST";
        request.ContentType = "application/json";
        request.Accept = "application/json";

        requestContent.encodedValue = encondedValue;
        requestContent.emailAddress = MYEMAIL_ADDRESS;
        requestContent.name = MYNAME;
        requestContent.webhookUrl = WEBHOOK_URL;
        requestContent.repoUrl = REPO_URL;

        serializedJsonContent = new JavaScriptSerializer().Serialize(requestContent);
        contentBytes = Encoding.ASCII.GetBytes(serializedJsonContent);
        request.ContentLength = contentBytes.Length;

        Stream dataStream = request.GetRequestStream();
        dataStream.Write(contentBytes, 0, contentBytes.Length);
        dataStream.Close();
        try {
            response = (HttpWebResponse)request.GetResponse();
            string responseStream = new StreamReader(response.GetResponseStream()).ReadToEnd();
            PostResponseEncoded postResponse = new JavaScriptSerializer().Deserialize<PostResponseEncoded>(responseStream);

            switch (postResponse.status) {
                case STATUS_SUCCESS:
                    lblSuccessCount.Text = (Int32.Parse(lblSuccessCount.Text) + 1).ToString();
                    break;
                case STATUS_CRASHANDBURN:
                    lblCrashAndBurnCount.Text = (Int32.Parse(lblCrashAndBurnCount.Text) + 1).ToString();
                    break;
                case STATUS_WINNER:
                    lblWinnerCount.Text = (Int32.Parse(lblWinnerCount.Text) + 1).ToString();
                    break;
            }
        } catch (WebException exc){
            Console.WriteLine("hola");
        }
    }
开发者ID:dmiranda2791,项目名称:AcklenSantaWarChallenge,代码行数:46,代码来源:getsecretphrase.aspx.cs

示例10: BuildReqStream

            private void BuildReqStream(ref HttpWebRequest webrequest)
            //This method build the request stream for WebRequest
            {
                byte[] bytes = Encoding.ASCII.GetBytes(Request);
                webrequest.ContentLength = bytes.Length;

                Stream oStreamOut = webrequest.GetRequestStream();
                oStreamOut.Write(bytes, 0, bytes.Length);
                oStreamOut.Close();
            }
开发者ID:pold500,项目名称:vk_downloader,代码行数:10,代码来源:BaseRequestStream.cs

示例11: WaitForConnection

    /// <summary>
    /// 向网络发出请求
    /// </summary>
    /// <param name="request">需要转换字符流</param>
    private static void WaitForConnection(out HttpWebRequest request)
    {
        request = (HttpWebRequest)HttpWebRequest.Create(serverURL);

        byte[] byteArray = Encoding.UTF8.GetBytes(JSON);
        request.Method = Method.POST.ToString();
        request.ContentType = Enctype;
        request.ContentLength = byteArray.Length;

        Stream dataStream = request.GetRequestStream();
        dataStream.Write(byteArray, 0, byteArray.Length);

        dataStream.Close();
    }
开发者ID:XWHQSJ,项目名称:Fights,代码行数:18,代码来源:HTTPClient.cs

示例12: PostRequest

    private string PostRequest(string url, string[] args, ref HttpWebRequest request)
    {
        ASCIIEncoding encoding = new ASCIIEncoding();

        string postData = "__EVENTTARGET=" + args[0] + "&__EVENTARGUMENT=" + args[1];
        postData += "&__VIEWSTATE=" + args[2] + "&__EVENTVALIDATION=" + args[3];
        postData += "&LogOn1$UserName=CLT" +
                "&LogOn1$Password=TEST";
               // "&LogOn1$LoginButton=" + Uri.EscapeDataString("Log In");

        //"&__EVENTARGUMENT=" + string.Empty +
        //"&__EVENTTARGET=" + string.Empty;
        txtPostBack.Text = postData;

        byte[] data = encoding.GetBytes(postData);

        request = (HttpWebRequest)WebRequest.Create(url);
        request.Method = "POST";
        request.ContentType = "application/x-www-form-urlencoded";
        request.ContentLength = data.Length;
        request.Referer = url;

        Stream newStream = request.GetRequestStream();
        // Send the data.
        try
        {
            newStream.Write(data, 0, data.Length);
            newStream.Close();
        }
        catch (Exception ex)
        {
            Response.Write(ex.StackTrace);
        }
        finally
        {
            newStream.Close();
        }

        return GetResponse(url, ref request);
    }
开发者ID:KPratap,项目名称:PropSolutions,代码行数:40,代码来源:Testpage.aspx.cs


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