Request Body missing in Post call from Pre-request script

I have a simple request that I want to send to my API. But before sending this request, I have to generate HMAC so that my request can be validated. So here what I really want to do is to chain 2 requests - (HMAC request β†’ my request). To generate HMAC, i am using https://dotnetfiddle.net/. To achieve this, i am using pm.sendRequest method in Pre-request Scripts. But every time a send a request to dotnetfiddle, it is giving me same result - β€œFatal Error: Public Main() method is required in a public class”. I checked console and found that Request body is missing in Post Request to β€œC# Online Compiler | .NET Fiddle”. Any help is appreciated. Thanks in advance

Pre-request Script -

var client_key = "some client key";
var client_secret = "some client secret";
var digest_url = "http://localhost:8444/mytestapi";

var code = "using System;\nusing System.Security.Cryptography;\nusing System.Text;\nnamespace HMAC\n{\n\tpublic class Program\n\t{\n\t\tpublic static void Main()\n\t\t{\n\t\t\tString method_type = "GET";\n\t\t\tString content_type = "null";\n\t\t\tString digest_url = "" + digest_url + "";\n\t\t\tString client_key = "" + client_key + "";\n\t\t\tString client_secret = "" + client_secret + "";\n\t\t\tstring x_auth = string.Empty;\n\t\t\tstring x_date = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss+0000");\n\t\t\tStringBuilder signatures = new StringBuilder();\n\t\t\tsignatures.Append(method_type).Append("\\\\n")\n\t\t\t.Append(content_type).Append("\\\\n")\n\t\t\t.Append(x_date).Append("\\\\n")\n\t\t\t.Append(digest_url);\n\t\t\tvar sec_key_bytes = Encoding.UTF8.GetBytes(client_secret);\n\t\t\tbyte[] sign = Encoding.UTF8.GetBytes(signatures.ToString());\n\t\t\tusing (HMACSHA256 hmac = new HMACSHA256(sec_key_bytes))\n\t\t\t{\n\t\t\t\tbyte[] signature_bytes = hmac.ComputeHash(sign);\n\t\t\t\tstring sign_hash = Convert.ToBase64String(signature_bytes);\n\t\t\t\tx_auth = string.Format("{0}:{1}", client_key, sign_hash);\n\t\t\t}\n\t\t\tConsole.WriteLine(x_date);\n\t\t\tConsole.WriteLine(x_auth);\n\t\t\tConsole.WriteLine(signatures);\n\t\t}\n\t}\n}";
pm.environment.set("HMAC_Code", code);

const hmacRequest = {
    url: 'https://dotnetfiddle.net/Home/Run',
    method: 'POST',
    header: {
        'Content-Type' : 'application/json'
    },
    body: {
        Compiler: 'Net45',
        ConsoleInputLines: [],
        Language: 'CSharp',
        MvcCodeBlock: {'Model': '', 'View': '', 'Controller': ''},
        MvcViewEngine: 'Razor',
        NuGetPackageVersionIds: '',
        OriginalCodeBlock: '',
        OriginalFiddleId: 'CsCons',
        OriginalMvcCodeBlock: {'Model': '', 'View': '', 'Controller': ''},
        OriginalNuGetPackageVersionIds: '',
        ProjectType: 'Console',
        TimeOffset: '5.5',
        UseResultCache: false,
        CodeBlock: pm.environment.get("HMAC_Code")
    },
};
pm.sendRequest(hmacRequest, function (err, res) {
    console.log("hmacRequest  ::  " + JSON.stringify(hmacRequest));
    console.log("res  ::  " + res);
});

Postman Console -

POST https://dotnetfiddle.net/Home/Run: {
  "Request Headers": {
    "content-type": "application/json",
    "user-agent": "PostmanRuntime/7.28.4",
    "accept": "*/*",
    "postman-token": "5f2681e6-aa1e-47b1-bf03-521c82a2de4b",
    "host": "dotnetfiddle.net",
    "accept-encoding": "gzip, deflate, br",
    "connection": "keep-alive",
    "content-length": "0"
  },
  "Response Headers": {
    "cache-control": "private",
    "content-type": "application/json; charset=utf-8",
    "server": "Microsoft-IIS/10.0",
    "x-aspnetmvc-version": "4.0",
    "x-aspnet-version": "4.0.30319",
    "request-context": "appId=cid-v1:12b08763-5c5a-4606-bd08-4079974aa642",
    "access-control-expose-headers": "Request-Context",
    "x-powered-by": "ASP.NET",
    "date": "Fri, 24 Sep 2021 09:48:57 GMT",
    "content-length": "1055",
    "age": "16",
    "connection": "keep-alive",
    "via": "HTTPS/1.1 localhost.localdomain"
  },
  "Response Body": "{\"Language\":1,\"ProjectType\":1,\"Compiler\":1,\"IsAutoRun\":false,\"IsReadonly\":false,\"CodeBlock\":null,\"OriginalCodeBlock\":null,\"ConsoleOutput\":\"Fatal Error: Public Main() method is required in a public class\\r\\n\",\"OriginalFiddleId\":null,\"NuGetPackageVersionIds\":\"\",\"HeaderDirectivePackageVersionIds\":null,\"OriginalNuGetPackageVersionIds\":null,\"Stats\":{\"RunAt\":\"9:48:43 am\",\"CompileTime\":\"0s\",\"ExecuteTime\":\"0.172s\",\"MemoryUsage\":\"0b\",\"CpuUsage\":\"0s\",\"IsResultCache\":false},\"TimeOffset\":0,\"NuGetPackageVersions\":[],\"HeaderDirectivePackageVersions\":[],\"IsConsoleInputRequested\":false,\"ConsoleInputLines\":null,\"MvcViewEngine\":0,\"MvcCodeBlock\":{\"Model\":null,\"View\":null,\"Controller\":null},\"OriginalMvcCodeBlock\":{\"Model\":null,\"View\":null,\"Controller\":null},\"WebPageHtmlOutput\":null,\"WebPageHtmlOutputId\":null,\"UserId\":null,\"UserDisplayName\":null,\"Name\":null,\"AccessType\":1,\"ForkCount\":0,\"IsInUserFavorites\":false,\"IsInUserFiddles\":false,\"ViewCount\":0,\"FavoriteCount\":0,\"HasErrors\":true,\"HasCompilationErrors\":false,\"IsConvertedFiddle\":false,\"UseResultCache\":false}"
}
'hmacRequest  ::  {"url":"https://dotnetfiddle.net/Home/Run","method":"POST","header":{"Content-Type":"application/json"},"body":{"Compiler":"Net45","ConsoleInputLines":[],"Language":"CSharp","MvcCodeBlock":{"Model":"","View":"","Controller":""},"MvcViewEngine":"Razor","NuGetPackageVersionIds":"","OriginalCodeBlock":"","OriginalFiddleId":"CsCons","OriginalMvcCodeBlock":{"Model":"","View":"","Controller":""},"OriginalNuGetPackageVersionIds":"","ProjectType":"Console","TimeOffset":"5.5","UseResultCache":false}}'
'res  ::  [object Object]'
GET http://localhost:8444/mytestapi: {
  "Network": {
    "addresses": {
      "local": {
        "address": "::1",
        "family": "IPv6",
        "port": 49930
      },
      "remote": {
        "address": "::1",
        "family": "IPv6",
        "port": 8444
      }
    }
  },
  "Request Headers": {
    "x-date": "Fatal Error: Public Main() method is required in a public class",
    "x-auth": "",
    "referer": "http://10.53.97.135:8444",
    "authorization": "Bearer eyJhbGciOiJIUzUxMiJ9.eyJndWlkIjoiOGQ3YjlmMTMtZGQ1MS0xMWViLWFhY2ItMDA1MDU2YjU3Y2Y5IiwiZG9tYWluTmFtZSI6ImdiIiwic3ViIjoiOGQ3YjlmMTMtZGQ1MS0xMWViLWFhY2ItMDA1MDU2YjU3Y2Y5IiwiaWF0IjoxNjMyNDc1MDM4LCJleHAiOjE2MzI0NzY4Mzh9.BX6cHed6uNaOlMCk3paHX8kjnTVT6aCKK9m6Bx_-DY_J3mzYlZC3X_CiTYYt8r8NdU2FkGxkKJhqO2pPXNurmg",
    "user-agent": "PostmanRuntime/7.28.4",
    "accept": "*/*",
    "postman-token": "5692d4ee-37e0-46b9-a62d-ae24cca30f06",
    "host": "localhost:8444",
    "accept-encoding": "gzip, deflate, br",
    "connection": "keep-alive"
  },
  "Request Body": "",
  "Response Headers": {
    "content-type": "text/html;charset=utf-8",
    "content-language": "en",
    "content-length": "796",
    "date": "Fri, 24 Sep 2021 09:48:58 GMT"
  },
  "Response Body": "<!doctype html><html lang=\"en\"><head><title>HTTP Status 404 – Not Found</title><style type=\"text/css\">h1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} h2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} h3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} body {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} b {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} p {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;} a {color:black;} a.name {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 404 – Not Found</h1></body></html>"
}

You probably got your answer by now but in case this helps anyone else.

You need to add this inside the body
mode:β€œraw”, raw:{payload}


const hmacRequest = {
    url: 'https://dotnetfiddle.net/Home/Run',
    method: 'POST',
    header: {
        'Content-Type' : 'application/json'
    },
    body: {
mode:"raw",
raw:{ 
        Compiler: 'Net45',
        ConsoleInputLines: [],
        Language: 'CSharp',
        MvcCodeBlock: {'Model': '', 'View': '', 'Controller': ''},
        MvcViewEngine: 'Razor',
        NuGetPackageVersionIds: '',
        OriginalCodeBlock: '',
        OriginalFiddleId: 'CsCons',
        OriginalMvcCodeBlock: {'Model': '', 'View': '', 'Controller': ''},
        OriginalNuGetPackageVersionIds: '',
        ProjectType: 'Console',
        TimeOffset: '5.5',
        UseResultCache: false,
        CodeBlock: pm.environment.get("HMAC_Code")
    }},
};