-1
I have the following service:
[HttpGet]
[Route("save")]
public async Task<dynamic> save(VendaModel[] venda, string CnpjEstab)
{
dynamic retorno = null;
VendaModel ultima = new VendaModel();
//TODO
}
I’m trying to consume this way:
public async static void SalvarArray(dynamic venda, string CnpjEstab)
{
string retorno;
try
{
var url = UrlBase.urlBase + "/GetVendas/save";
var a = new { venda, CnpjEstab };
var json = JsonConvert.SerializeObject(a);
var stringContent = new StringContent(json, UnicodeEncoding.UTF8, "application/json");
HttpClient req = new HttpClient();
HttpResponseMessage resp = await req.PostAsync(url, stringContent);
if (resp.StatusCode == HttpStatusCode.OK)
{
retorno = resp.Content.ReadAsStringAsync().GetAwaiter().GetResult();
}
}
catch (Exception err)
{
GeraLogError.GeraLog("GetVendas", MethodBase.GetCurrentMethod().Name, err.Message);
retorno = err.Message;
}
//return retorno;
}
but it is not working, the application is simply aborted (without any warning) , does not fall into the debug of the Api, has something wrong in the code ?
I’m using C#
Hello, friend! Before trying to help you, to rule out any problems in that sense, is the API up and running? If yes, you can make explicit where your debug is stopped?
– rammonzito
hello, this working yes, I modified the method to receive only one string, and tested with Postman, it worked right. Debug is interrponpid on this line: Httpresponsemessage Resp = await req.Postasync(url, stringContent);, here stops and does nothing else, does not arrive at the api, not from the error message, simply to.
– alessandre martins
Your var url and is set to what value after concatenation?
– rammonzito
http://localhost:64785/Getvendas/save
– alessandre martins