Asp.net core 从mobile将用户注册到.net core
我尝试在.NETCore中使用启用的身份和成员系统注册来自xamarin的用户。它返回true,但没有用户在数据库中注册。 此外,我还查看了MVC网站,一切正常 我的代码是Asp.net core 从mobile将用户注册到.net core,asp.net-core,Asp.net Core,我尝试在.NETCore中使用启用的身份和成员系统注册来自xamarin的用户。它返回true,但没有用户在数据库中注册。 此外,我还查看了MVC网站,一切正常 我的代码是 using (var client = new HttpClient()) { var model = new RegisterBindingModel { Emai
using (var client = new HttpClient())
{
var model = new RegisterBindingModel
{
Email = email,
Password = password,
ConfirmPassword = confirmPassword
};
var json = JsonConvert.SerializeObject(model);
HttpContent httpContent = new StringContent(json);
httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
var response = await client.PostAsync(
Constants.SignalrEndpointAddress + "Account/Register", httpContent);
if (response.IsSuccessStatusCode)
{
return true;
}
}
问题出在StringContent中,我的代码最终是这样的:
using (var client = new HttpClient())
{
var model = new Dictionary<string, string>
{
{"Email", email },
{"Password", password},
{"ConfirmPassword", confirmPassword},
};
var httpContent = new FormUrlEncodedContent(model);
var response = await client.PostAsync(
Constants.EndpointAddress + "Account/Register", httpContent);
if (response.IsSuccessStatusCode)
{
return true;
}
}
使用(var-client=new-HttpClient())
{
var模型=新字典
{
{“Email”,Email},
{“密码”,密码},
{“ConfirmPassword”,ConfirmPassword},
};
var httpContent=新FormUrlEncodedContent(模型);
var response=wait client.PostAsync(
Constants.EndpointAddress+“帐户/寄存器”,httpContent);
if(响应。IsSuccessStatusCode)
{
返回true;
}
}
感谢调试您的api。我尝试过,但当我从emulator启动请求时,visual studio dos没有介入代码,这是由chromedebug解决的问题,在更新vs到新版本后,但新的问题是控制器方法中的模型始终为空,因此,模型存在验证错误,可能我的HTTP请求需要额外的配置。