Nae*_*aza 5 asp.net servicestack
我正在使用以下代码来验证用户在我的asp.net应用程序中使用ServiceStack基本身份验证提供程序并接收serration异常.如果有人解决了这个问题,请回答.谢谢.
我在我的asp.net应用程序中使用以下代码:
<asp:Button ID="btnAuth" runat="server" OnClick="btnAuth_Click" Text="Authenticate"/>
Run Code Online (Sandbox Code Playgroud)
我在代码隐藏文件中的clien.Post方法上收到异常.
protected void btnAuth_Click(object sender, EventArgs e)
{
try
{
var baseUrl = Request.Url.GetLeftPart(UriPartial.Authority) + "/api";
var client = new JsonServiceClient(baseUrl);
var authResponse = client.Post<AuthResponse>(new Auth { UserName = "admin", Password = "12345" });
if (authResponse.ResponseStatus.ErrorCode == null)
{
//Do Something here
}
}
catch (WebServiceException ex)
{
throw ex;
}
}
Run Code Online (Sandbox Code Playgroud)
Followin是我在clien.Post方法上收到的Exeception Detail :
[SerializationException: Type definitions should start with a '{', expecting serialized type 'AuthResponse', got string starting with:
Run Code Online (Sandbox Code Playgroud)
小智 1
读取“期望序列化类型‘X’,获取字符串开头为:”的序列化异常意味着序列化程序尝试从空字符串而不是正确的 json 格式字符串创建对象(“{ Class:{Property:{Sub:价值}}}”)。
在这种情况下,最可能的原因是baseUrl处的服务器没有对 POST 请求返回响应(解释为空字符串)。可能是 URL 配置错误或服务器端出现异常?
| 归档时间: |
|
| 查看次数: |
2284 次 |
| 最近记录: |