如何在c#中计算POST请求的字节数?

如何在c#中计算POST请求的字节数?,c#,asp.net,post,arduino,webapi,C#,Asp.net,Post,Arduino,Webapi,我正在使用POST方法使用PLIVO发送SMS,但问题是在从另一个工具Arduino发送之前,我需要知道请求字节。我可以在响应调试器中看到Request.ContentLenght是156,但在Arduino中提供字节时,这是不正确的 请检查以下代码以供参考,我需要知道有效负载大小(字节)的请求 using Plivo; using Plivo.API; using RestSharp; using System; using System.Collections.Generic; names

我正在使用POST方法使用PLIVO发送SMS,但问题是在从另一个工具Arduino发送之前,我需要知道请求字节。我可以在响应调试器中看到Request.ContentLenght是156,但在Arduino中提供字节时,这是不正确的

请检查以下代码以供参考,我需要知道有效负载大小(字节)的请求

using Plivo;
using Plivo.API;
using RestSharp;
using System;
using System.Collections.Generic;

namespace PlivoSMSApp
{
  class Program
{
    static void Main(string[] args)
    {
        Program obj = new Program();
        bool isSMSSent = obj.SendSms("+91852762678", "+420603797597", "Send SMS using Plivo");
    }


    public bool SendSms(string from, string to, string text)
    {
        string authId = "TestAuthID";
        string autoToken = "TestAuthToken";
        RestAPI plivo = new RestAPI(authId, autoToken);
        IRestResponse resp = plivo.send_message(new Dictionary<string, string>()
        {
            { "src", ""+from+"" }, // Sender's phone number with country code
            { "dst", ""+to+"" }, // Receiver's phone number with country code
            { "text", ""+text+"" }, // Your SMS text message
            // To send Unicode text
            // {"text", "こんにちは、元気ですか?"} // Your SMS text message - Japanese
            // {"text", "Ce est texte généré aléatoirement"} // Your SMS text message - French
            { "url", "http://google.com/delivery_report"}, // The URL to which with the status of the message is sent
            { "method", "POST"} // Method to invoke the url
        });
        if (!String.IsNullOrEmpty(resp.ErrorMessage))
            return false;
        return true;
    }
}
使用Plivo;
使用Plivo.API;
使用RestSharp;
使用制度;
使用System.Collections.Generic;
名称空间PlivoSMSApp
{
班级计划
{
静态void Main(字符串[]参数)
{
Program obj=新程序();
bool issmsent=obj.SendSms(“+91852762678”,“+420603797597”,“使用Plivo发送短信”);
}
公共bool SendSms(字符串从、字符串到、字符串文本)
{
字符串authId=“TestAuthID”;
字符串autoToken=“TestAuthToken”;
RestAPI plivo=新RestAPI(authId,autoToken);
IRestResponse resp=plivo.send_消息(新字典()
{
{“src”、“+from+”}、//发件人的电话号码及国家/地区代码
{“dst”,“”+至+“”},//带国家代码的接收者电话号码
{“text”,“+text+”},//您的短信
//发送Unicode文本的步骤
//{“文本”こんにちは、元気ですか?"} // 你的短信-日语
//{“text”,“Ce est texte généréaléatoirement”}//您的短信-法语
{“url”http://google.com/delivery_report“},//向其发送状态为消息的URL
{“method”,“POST”}//调用url的方法
});
如果(!String.IsNullOrEmpty(resp.ErrorMessage))
返回false;
返回true;
}
}

}

为什么需要它?在哪里需要它?找不到它…@tvdias我需要它作为我的另一个工具,它是Arduino,我需要在调用之前调用POST request,我需要提供我正在发送的请求字节。因此,我使用C检查请求是否正确形成。但是我没有看到请求大小。请添加Arduino的代码片段?如果我没弄错的话,你只是用c#来计算帖子的大小?如果是这样的话,在Arduino和c#上可能不一样。此外,你可能需要正文长度或正文+页眉长度,这取决于它是如何完成的。