这是我的错误:
D/Retrofit: java.lang.IllegalArgumentException: Sales.updateDeliveryLine: Only one HTTP method is allowed. Found: PUT and PUT.
at retrofit.RestMethodInfo.methodError(RestMethodInfo.java:123)
at retrofit.RestMethodInfo.parseMethodAnnotations(RestMethodInfo.java:155)
at retrofit.RestMethodInfo.init(RestMethodInfo.java:133)
at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:294)
at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:220)
at retrofit.RestAdapter$RestHandler$2.obtainResponse(RestAdapter.java:278)
at retrofit.CallbackRunnable.run(CallbackRunnable.java:42)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at retrofit.Platform$Android$2$1.run(Platform.java:142)
at java.lang.Thread.run(Thread.java:818)
这是我在Android Studio中的代码:
@PUT("/salesinsight/GetDeliveryScheduleLineRow/")
public void updateDeliveryLine(@Path("id") int id, @Body API_DeliveryScheduleLines api_deliveryScheduleLines,
Callback<API_DeliveryScheduleLines> callback);
这是我在Web Api中的代码:
// PUT: api/GetDeliveryScheduleLineRow/5
[ResponseType(typeof(void))]
public IHttpActionResult PutDelivery_Schedule_Lines(int id, Delivery_Schedule_Lines delivery_Schedule_Lines)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
if (id != delivery_Schedule_Lines.ID)
{
return BadRequest();
}
db.Entry(delivery_Schedule_Lines).State = EntityState.Modified;
try
{
db.SaveChanges();
}
catch (DbUpdateConcurrencyException)
{
if (!Delivery_Schedule_LinesExists(id))
{
return NotFound();
}
else
{
throw;
}
}
return StatusCode(HttpStatusCode.NoContent);
}
每次尝试更新错误时都会显示。
答案 0 :(得分:0)
首先,在您的PUT方法中,您将id作为Integer传递。但是你没有在你的API路径中提到id,这是缺少的。希望它有所帮助。
@PUT("/salesinsight/GetDeliveryScheduleLineRow/{id}")
public void updateDeliveryLine(@Path("id") int id, @Body API_DeliveryScheduleLines api_deliveryScheduleLines,
Callback<API_DeliveryScheduleLines> callback);