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


C# WebRequest.GetRequestStream方法代码示例

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


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

示例1: GetHttpWebResponse

 private static string GetHttpWebResponse(WebRequest httpWebRequest, string postData)
 {
     StreamWriter requestWriter = new StreamWriter(httpWebRequest.GetRequestStream());
     try
     {
         requestWriter.Write(postData);
     }
     finally
     {
         requestWriter.Close();
     }
     return GetHttpWebResponse(httpWebRequest);
 }
开发者ID:coolcode,项目名称:app,代码行数:13,代码来源:HttpPost.cs

示例2: SendPostContents

    /// <summary>
    /// Sends the body text up to the server
    /// </summary>
    /// <param name="request"></param>
    /// <param name="bodyText"></param>
    protected static void SendPostContents(WebRequest request, string bodyText)
    {
        request.Method = "POST";
        // Set the ContentType property of the WebRequest.
        request.ContentType = "application/x-www-form-urlencoded";
        // Set the ContentLength property of the WebRequest.
        byte[] byteArray = Encoding.UTF8.GetBytes(bodyText);
        request.ContentLength = byteArray.Length;

        // Get the request stream.
        var dataStream = request.GetRequestStream();
        // Write the data to the request stream.
        dataStream.Write(byteArray, 0, byteArray.Length);
        // Close the Stream object.

        dataStream.Close();
    }
开发者ID:yaswanth369,项目名称:TabMigrate,代码行数:22,代码来源:TableauServerRequestBase.cs

示例3: GetRequestStreamAsync

 public override Task<Stream> GetRequestStreamAsync(WebRequest request) => Task.Run(() => request.GetRequestStream());
开发者ID:Corillian,项目名称:corefx,代码行数:1,代码来源:FileWebRequestTest.cs

示例4: SendHttpRequestContents_Inner

    /// <summary>
    /// Sends the body text up to the server
    /// </summary>
    /// <param name="request"></param>
    /// <param name="bodyText"></param>
    private static void SendHttpRequestContents_Inner(WebRequest request, string bodyText, string httpMethod = "POST")
    {
        request.Method = httpMethod;
        // Set the ContentType property of the WebRequest.
        request.ContentType = "application/xml;charset=utf-8"; //[2016-06-17] We want to be very explicit on the content type; to give servers very clear instructions on how to parse
        // Set the ContentLength property of the WebRequest.
        byte[] byteArray = Encoding.UTF8.GetBytes(bodyText);
        request.ContentLength = byteArray.Length;

        // Get the request stream.
        var dataStream = request.GetRequestStream();
        // Write the data to the request stream.
        dataStream.Write(byteArray, 0, byteArray.Length);
        // Close the Stream object.

        dataStream.Close();
    }
开发者ID:tableau,项目名称:TabMigrate,代码行数:22,代码来源:TableauServerRequestBase.cs

示例5: Ping

    public bool Ping(string osVersion, string cjVersion, string machineID)
    {
        requestPingAborting = false;

        // Create a request using a URL that can receive a post.
        requestPing = WebRequest.Create (serverUrl + "/ping");

        // Set the Method property of the request to POST.
        requestPing.Method = "POST";

        // Set the ContentType property of the WebRequest.
        requestPing.ContentType = "application/json";

        // Creates the json object
        JsonObject json = new JsonObject();
        json.Add("os_version", osVersion);
        json.Add("cj_version", cjVersion);
        json.Add("machine_id", machineID);

        // Converts it to a String
        String js = json.ToString();

        // Writes the json object into the request dataStream
        Stream dataStream;
        try {
            dataStream = requestPing.GetRequestStream ();
        } catch {
            this.ResultMessage =
                string.Format(Catalog.GetString("You are not connected to the Internet\nor {0} server is down."),
                serverUrl);
            return false;
        }
        if(requestPingAborting) {
            LogB.Information("Aborted from PingAbort");
            return false;
        }

        dataStream.Write (Encoding.UTF8.GetBytes(js), 0, js.Length);

        dataStream.Close ();

        // Get the response.
        WebResponse response;
        try {
            response = requestPing.GetResponse ();
        } catch {
            this.ResultMessage =
                string.Format(Catalog.GetString("You are not connected to the Internet\nor {0} server is down."),
                serverUrl);
            return false;
        }
        if(requestPingAborting) {
            LogB.Information("Aborted from PingAbort");
            return false;
        }

        // Display the status (will be 201, CREATED)
        Console.WriteLine (((HttpWebResponse)response).StatusDescription);

        // Clean up the streams.
        dataStream.Close ();
        response.Close ();

        this.ResultMessage = "Ping sent.";
        return true;
    }
开发者ID:GNOME,项目名称:chronojump,代码行数:66,代码来源:json.cs


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