C# 从Webforms页面.Net框架使用Refit调用API WEB

C# 从Webforms页面.Net框架使用Refit调用API WEB,c#,refit,C#,Refit,我可以从WebForms页面使用Refit来连接RESTWebAPI方法。举个例子 这是我的代码,我得到以下错误: protected async void btnAcceder_Click(object sender, EventArgs e) { var api = RestService.For<ILogin>("https://WebApi.Test"); var login = await api.GetLogin(new Login {

我可以从WebForms页面使用Refit来连接RESTWebAPI方法。举个例子

这是我的代码,我得到以下错误:

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);
  }
}
protected async void btnAcceder\u单击(对象发送方,事件参数e)
{
var api=RestService.For(“https://WebApi.Test");
var login=await api.GetLogin(新登录名{UserName=txtmail.Text,Password=TxtPassword.Text});
if(login==null)
重定向(“Error.aspx?Err=102”);
会话[“Usuario”]==login.Token;
重定向(“Dashboard.aspx”);
}
命名空间仪表板.Sdk
{
使用Dashboard.Common.Modelos;
使用改装;
使用System.Threading.Tasks;
公共接口ILogin
{
[获取(“/comGpsGate/api/v.1/test#/Tokens”)]
任务GetLogin([Body]登录名);
}
}
错误


错误服务于应用程序“/”。 不存在任何文本内容。 描述:不可控制的情况除外。修订《关于获取错误信息和原产地信息的法律法规》(el seguimiento de la pila para obtener más información acerca del error y dónde se originóen el código)

例外情况说明:System.Net.ProtocolViolationException:不存在文本内容

código fuente错误:

利尼亚28:利尼亚29:var api= RestService.For(“https://WebApi.Test"); 利尼亚30:var login=wait api.GetLogin(新登录名{UserName=TxtEmail.Text, Password=TxtPassword.Text});莱尼亚31:莱尼亚32:

原始档案:D:\desarrolos\Sinergygroup\Dashborad GPS\DashBSauro\Login.aspx.cs Línea:30

皮拉之家:

[ProtocolViolationException:No se puede enviar contenido text con.] [详细说明]
System.Net.HttpWebRequest.CheckProtocol(布尔onRequestStream)+556 System.Net.HttpWebRequest.BeginGetRequestStream(异步回调 回调,对象状态)+85
System.Net.Http.HttpClientHandler.StartGettingRequestStream(RequestState 州)+129
System.Net.Http.HttpClientHandler.PrepareAndStartContentUpload(RequestState 州)+311
System.Runtime.CompilerServices.TaskWaiter.ThrowForNonSuccess(任务 任务)+102
System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)+64
重新安装.d.MoveNext()+708
System.Runtime.CompilerServices.TaskWaiter.ThrowForNonSuccess(任务 任务)+102
System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务 task)+64 System.Runtime.CompilerServices.TaskWaiter`1.GetResult() +29 d:\desarrolos\Sinergygroup\Dashborad GPS\DashBSauro\Login.aspx.cs:30中的DashBSauro.d\uuu 2.MoveNext() System.Runtime.CompilerServices.c.b\u 6\u 0(对象状态) +54 System.Web.c__DisplayClass22_0.b__0()+15 System.Web.Util.SynchronizationHelper.SafeWrapCallback(操作) +89 System.Runtime.CompilerServices.TaskWaiter.ThrowForNonSuccess(任务 任务)+102
System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)+64
System.Web.Util.WithIncachellableCallbackTaskWaiter.GetResult()+30
System.Web.UI.d_523.MoveNext()+5878


我发现了问题,这可能与您的问题有关。您将登录参数定义为[Body]。get请求不允许这样做。是否可能,您的登录方法是post请求而不是get请求,或者参数应该作为查询参数而不是正文传递?

请将问题的所有部分翻译为英语。您可以为ILogin界面添加源代码吗?好,代码已添加。您是否检查了作者正式提供的此示例项目或重新安装https://github.com/reactiveui/refit/tree/master/samples