Android 响应状态代码不表示成功:';400';(';请求错误';)
我想在我的android xamarin应用程序中使用refit将数据发布到API。我已经在Postman测试了API,它工作正常,但在android应用程序中,我收到了异常错误的请求,这是我的android代码。我添加了接口和模型,我不知道问题出在哪里Android 响应状态代码不表示成功:';400';(';请求错误';),android,api,refit,Android,Api,Refit,我想在我的android xamarin应用程序中使用refit将数据发布到API。我已经在Postman测试了API,它工作正常,但在android应用程序中,我收到了异常错误的请求,这是我的android代码。我添加了接口和模型,我不知道问题出在哪里 public interface RequestAPI { [Post("/request")] Task<create_request> submit([Body] create_request request);
public interface RequestAPI
{
[Post("/request")]
Task<create_request> submit([Body] create_request request);
}
requestAPI= RestService.For<RequestAPI>("http://courier-magconsulting.azurewebsites.net/api");
button.Click += async delegate
{
try
{
create_request request = new create_request();
request.PickUpPhone = "7664554";
request.DownPayment = 89;
request.DeliveryFees = 56.8;
request.Note = "i need a help!";
request.RequestID = 88; // replace the value yourself
request.DekiveryLocationLatitude = 2323;
request.DeliveryLocationLongitude = 232;
request.PickUpLocationLatitude = 898;
request.PickUpLocationLongitude = 1123;
BroadcastType type = new BroadcastType();
type.Name = "All";
type.ID = 60; // replace the value yourself
request.BroadcastType = type;
Cargosize size = new Cargosize();
size.Name = "Small";
size.ID = 1; // replace the value yourself
request.Cargosize = size;
Cargoweight weight = new Cargoweight();
weight.Name = "Large";
weight.ID = 2; // replace the value yourself
request.CargoWeight = weight;
Sender sender_ = new Sender();
sender_.Name = "Ahmad";
sender_.SenderID = 1; // replace the value yourself
sender_.Phone = "8788";
sender_.SocialID = "8787";
sender_.RatingAvg = 5;
SenderStatus status = new SenderStatus();
status.ID = 1;
status.Name = "Active";
sender_.Senderstatus = status;
request.Sender = sender_;
create_request result = await requestAPI.submit(request);
Toast.MakeText(this, "Request created", ToastLength.Long).Show();
}
catch(Exception ex)
{
Toast.MakeText(this, ex.Message, ToastLength.Long).Show();
}
};
公共接口请求API
{
[发布(“/请求”)]
任务提交([正文]创建请求);
}
requestAPI=RestService.For(“http://courier-magconsulting.azurewebsites.net/api");
按钮。单击+=异步委托
{
尝试
{
create_request request=新建create_request();
request.pickuphone=“7664554”;
首期付款=89;
request.DeliveryFees=56.8;
request.Note=“我需要帮助!”;
request.RequestID=88;//自己替换该值
request.dekiverylocationlatude=2323;
request.deliveryLocation经度=232;
request.pickuplocationlation=898;
request.PickUpLocationLongitude=1123;
BroadcastType=新的BroadcastType();
type.Name=“全部”;
type.ID=60;//自己替换该值
request.BroadcastType=类型;
货码尺寸=新货码尺寸();
size.Name=“小”;
size.ID=1;//自己替换该值
请求。货物尺寸=尺寸;
货物重量=新货物重量();
weight.Name=“大”;
weight.ID=2;//自己替换该值
request.CargoWeight=重量;
发送方\发送方=新发送方();
发送方名称=“Ahmad”;
sender\uu0.SenderID=1;//自己替换该值
发送方\ uuu.Phone=“8788”;
发送者社交ID=“8787”;
发送器额定值VG=5;
SenderStatus状态=新的SenderStatus();
status.ID=1;
status.Name=“活动”;
发送方\发送方状态=状态;
request.Sender=Sender;
创建请求结果=等待请求API.submit(请求);
Toast.MakeText(这是“创建的请求”,ToastLength.Long).Show();
}
捕获(例外情况除外)
{
Toast.MakeText(这个,例如Message,ToastLength.Long).Show();
}
};