API一直返回代码500

时间:2017-11-25 19:43:34

标签: java android post retrofit apiary

我的任务是使用POST将数据发送到API(养蜂场)。我正在使用改造,当我发布API时返回代码500。

我的Retrofit客户端方法如下所示:

@POST("api/employees")
Call<Employee> createEmployee(@Body Employee e);

我打电话是这样的:

EmployeeClient client = retrofit.create(EmployeeClient.class);
    Call<Employee> call = client.createEmployee(employee);

    call.enqueue(new Callback<Employee>() {
        @Override
        public void onResponse(Call<Employee> call, Response<Employee> response) {
            Toast.makeText(CreateEmployeeActivity.this, "code" + response.code(), Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onFailure(Call<Employee> call, Throwable t) {
            Toast.makeText(CreateEmployeeActivity.this, "Something wrong", Toast.LENGTH_SHORT).show();
        }
    });

当我看到蜂房检查员对POST的期望值是这样的:

+ Part (name="json")
{
    "name": "John",
    "department": "IT",
    "address": "Somewhere",
    "photoUrl": "http://www.example.com/tesing/employees/65/photo"
}
+ Part (name="photo"; filename="filename.jpg")

如果我查看POST说明,photoUrl和照片是可选的,所以在我的POST中我发送没有照片文件的员工。

0 个答案:

没有答案