Reputation: 27
I can use Refit from a WebForms Page, to connect with a rest web api method. Some example?
This is my code and I get the following error:
protected async void btnAcceder_Click(object sender, EventArgs e)
{
var api = RestService.For<ILogin>("https://WebApi.Test");
var login = await api.GetLogin(new Login { UserName = TxtEmail.Text, Password = TxtPassword.Text });
if ( login==null )
Response.Redirect("Error.aspx?Err=102");
Session["Usuario"] = = login.Token;
Response.Redirect("Dashboard.aspx");
}
namespace Dashboard.Sdk
{
using Dashboard.Common.Modelos;
using Refit;
using System.Threading.Tasks;
public interface ILogin
{
[Get("/comGpsGate/api/v.1/test#/Tokens")]
Task<ApiResponse<AuthSuccessResponse>> GetLogin([Body] Login login);
}
}
ERROR
Error de servidor en la aplicación '/'. No se puede enviar contenido textual con este tipo de verbo. Descripción: Excepción no controlada al ejecutar la solicitud Web actual. Revise el seguimiento de la pila para obtener más información acerca del error y dónde se originó en el código.
Detalles de la excepción: System.Net.ProtocolViolationException: No se puede enviar contenido textual con este tipo de verbo.
Error de código fuente:
Línea 28: Línea 29: var api = RestService.For("https://WebApi.Test"); Línea 30: var login = await api.GetLogin(new Login { UserName = TxtEmail.Text, Password = TxtPassword.Text }); Línea 31: Línea 32:
Archivo de origen: D:\Desarrollos\Sinergygroup\Dashborad GPS\DashBSauro\Login.aspx.cs Línea: 30
Seguimiento de la pila:
[ProtocolViolationException: No se puede enviar contenido textual con este tipo de verbo.]
System.Net.HttpWebRequest.CheckProtocol(Boolean onRequestStream) +556 System.Net.HttpWebRequest.BeginGetRequestStream(AsyncCallback callback, Object state) +85
System.Net.Http.HttpClientHandler.StartGettingRequestStream(RequestState state) +129
System.Net.Http.HttpClientHandler.PrepareAndStartContentUpload(RequestState state) +311
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +102
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +64
Refit.<b__0>d.MoveNext() +708
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +102
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +64 System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() +29 DashBSauro.<btnAcceder_Click>d__2.MoveNext() in D:\Desarrollos\Sinergygroup\Dashborad GPS\DashBSauro\Login.aspx.cs:30 System.Runtime.CompilerServices.<>c.b__6_0(Object state) +54 System.Web.<>c__DisplayClass22_0.b__0() +15 System.Web.Util.SynchronizationHelper.SafeWrapCallback(Action action) +89 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +102
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +64
System.Web.Util.WithinCancellableCallbackTaskAwaiter.GetResult() +30
System.Web.UI.d__523.MoveNext() +5878
Upvotes: 0
Views: 710
Reputation: 1163
I found this issue, that could be connected to your problem. You define the login parameter as [Body]. This is not allowed for get requests. Is it possible, that your login method is a post request instead of a get request or that the parameters should be passed as query parameters instead of a body?
Upvotes: 1