Sending form to Pagseguro

1

I have this form

@using (Html.BeginForm("PacoteAdd", "Pacote"))
        {
        <input type="hidden" name="email_cobranca" value="*****@hotmail.com" />
        <input type="hidden" name="tipo" value="CBR" />
        <input type="hidden" name="moeda" value="BRL" />
        <input type="hidden" name="item_id" value="@item.PacoteID" />
        <input type="hidden" name="item_descr" value="@item.Titulo" />
        <input type="hidden" name="item_quant" value="1" />
        <input type="hidden" name="item_valor" value="@item.valor" />
        <input type="image" name="submit" src="https://p.simg.uol.com.br/out/pagseguro/i/botoes/pagamentos/99x61-comprar-assina.gif"alt="Pague com PagSeguro - é rápido, grátis e seguro!" />
}

and this code in the controller

[HttpPost]
public void PacoteAdd(FormCollection fomr)
{
     string email_cobranca = Request.Form["email_cobranca"];
     string tipo = Request.Form["tipo"];
     string moeda = Request.Form["moeda"];
     string item_id = Request.Form["item_id"];
     string item_descr = Request.Form["item_descr"];
     string item_quant = Request.Form["item_quant"];
     string item_valor = Request.Form["item_valor"];
}

and you would need to submit this form in the link

  

link

because the original code for the button would be this below

<form target="pagseguro" method="post" action="https://sandbox.pagseguro.uol.com.br/checkout/checkout.jhtml">
      <input type="hidden" name="email_cobranca" value="*****@hotmail.com" />
      <input type="hidden" name="tipo" value="CBR" />
      <input type="hidden" name="moeda" value="BRL" />
      <input type="hidden" name="item_id" value="@item.PacoteID" />
      <input type="hidden" name="item_descr" value="@item.Titulo" />
      <input type="hidden" name="item_quant" value="1" />
      <input type="hidden" name="item_valor" value="@item.valor" />
      <input type="image" name="submit" src="https://p.simg.uol.com.br/out/pagseguro/i/botoes/pagamentos/99x61-comprar-assina.gif"alt="Pague com PagSeguro - é rápido, grátis e seguro!" />
</form>

What should I use to send?

    
asked by anonymous 09.11.2016 / 03:11

1 answer

1

Only include the external url in Html.BeginForm :

@Html.BeginForm(null, null, FormMethod.Post, new {@action="https://sandbox.pagseguro.uol.com.br/checkout/checkout.jhtml"}
)
{
... aqui vão os inputs e botão submit
}

To post data from the controller you can use HttpClient :

var parametros = new List<KeyValuePair<string, string>>();
parametros.Add(new KeyValuePair<string, string>("email_cobranc", "*****@hotmail.com"));
// Adicionar os outros parâmetros

var content = new System.Net.Http.FormUrlEncodedContent(parametros);
var cliente = new System.Net.Http.HttpClient { BaseAddress = new Uri("https://sandbox.pagseguro.uol.com.br") };

var response = cliente.PostAsync("/checkout/checkout.jhtml", content).Result;
if (response.IsSuccessStatusCode)
{
    // aqui você trata o retorno
}

You may need to add a line to avoid certificate errors, since your link is https .

    
09.11.2016 / 13:12