json - 发送 JSON Put 方法的错误 404 - Xamarin.Forms
问题描述
我正在 Xamarin Forms 中开发一个移动应用程序,并且我的 Put 方法正在恢复 404 状态时遇到问题,但是如果我在 Postman 上提出请求,它运行良好......我看不到问题......
这是请求
public async Task<UserHasGamification> AddPointsToUser(UserHasGamification userHasGamification)
{
HttpClient client = new HttpClient();
client.BaseAddress = new Uri("http://192.168.2.202:8080/api/UserGamification");
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
// Converte seu objeto para formato Json
string json = JsonConvert.SerializeObject(userHasGamification);
// Espera o resultado
HttpResponseMessage response = await client.PutAsync("userHasGamification", new StringContent(json, Encoding.UTF8, "application/json"));
if (response.IsSuccessStatusCode)
{
return userHasGamification;
}
return userHasGamification;
}
这是我的课
public class UserHasGamification
{
public int UserID { get; set; }
public string Level { get; set; }
public string Points { get; set; }
}
这是错误:
{StatusCode: 404, ReasonPhrase: 'Not Found', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
Cache-Control: no-cache
Date: Sat, 29 Aug 2020 08:46:04 GMT
Pragma: no-cache
Server: Microsoft-IIS/10.0
X-Android-Received-Millis: 1598690768707
X-Android-Response-Source: NETWORK 404
X-Android-Sent-Millis: 1598690768679
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Content-Length: 122
Content-Type: application/json; charset=utf-8
Expires: -1
}}
get 方法工作正常……但 PUT 方法没有……我不太明白为什么。
有人可以帮帮我吗?
解决方案
推荐阅读
- php - PHP 在匹配文本之前提取数字
- amazon-redshift - 如何在最后一次修改表的日期时检查红移?
- python - 如何修复这个无法运行的 Python 代码?
- java - 泛型与继承
- oracle - ORA-12154 Oracle DB Windows 无法连接 SQLPlus
- html - 如何在css中制作动画加载器?
- cassandra - -bash:cqlsh:在cqlsh之外运行cql命令时找不到命令错误
- python - flask_rq, redis, rq 将作业移动到 FailedJobRegistry 主力进程意外终止(waitpid 返回无)
- api - Identity Server 4 Postman 请求令牌不起作用
- algorithm - 如何在 MQL4 / MT4 中对很多指数进行分组?