Home > Net >  Send RestClient through Function Azure VS Code
Send RestClient through Function Azure VS Code

Time:02-10

I am trying to make a post request with c# through the Azure HttpTrigger function. Only that when executing it sends me thousands of errors. Can someone help me here?

This is my code:

using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;

namespace Admin
{
    public static class addTimbres
    {
        public static readonly string url = "https://dev.facturacfdi.mx:8083/admindigital/WSDistribuidoresServices?wsdl";

        [FunctionName("addTimbres")]
        public static async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req)
        {
            string username = "distribuidor1";
            string pass = "r*6Og80*2";
            string id = req.Query["id"];
            string cantidad = req.Query["cantidad"];
            string precio = req.Query["precio"];
            string tipo = req.Query["tipoServicio"];

            var client = new RestClient("https://dev.facturacfdi.mx:8083/admindigital/WSDistribuidoresServices?wsdl");
            client.Timeout = -1;
            var request = new RestRequest(Method.POST);
            request.AddHeader("Content-Type", "text/xml");
            request.AddHeader("Cookie", "AWSELB=9967379D183B464F07472AD23944C79D1D256893C16F7531AC9AEC11DFCF25BB286EED0AA8BE0779B4925DB1440897B768AE03876F852C644560C840DC57CFDF50A6CA647F; AWSELBCORS=9967379D183B464F07472AD23944C79D1D256893C16F7531AC9AEC11DFCF25BB286EED0AA8BE0779B4925DB1440897B768AE03876F852C644560C840DC57CFDF50A6CA647F");
            var body =
            @"<Envelope xmlns=""http://schemas.xmlsoap.org/soap/envelope/"">
            "   "\n"  
            @"    <Body> 
            "   "\n"  
            @"        <getUsuarios xmlns=""http://servicios.ws.distribuidores.forsedi.mx/"">
            "   "\n"  
            @"            <username xmlns="""">distribuidor1</username>
            "   "\n"  
            @"            <password xmlns="""">r*6Og80*2</password>
            "   "\n"  
            @"        </getUsuarios>
            "   "\n"  
            @"    </Body>
            "   "\n"  
            @"</Envelope>";
            request.AddParameter("text/xml", body, ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            Console.WriteLine(response.Content);

        }



    }
}

I understand that RestClient is used for this case, but I can't find out how it is implemented with Azure Functions.

Thanks.

CodePudding user response:

  •  Tags:  
  • Related