gpt4 book ai didi

java - 如何使用 Retrofit 找到正确的端点以将 JSON 对象 POST 到 JSONbin

转载 作者:行者123 更新时间:2023-12-02 08:55:55 24 4
gpt4 key购买 nike

我在 JSONbin.io 中有以下结构的 JSON 对象。

{
"beneficiaries": [
{
"name": "Brian",
"staff_no": "12",
"id": "11111111"
}],
"users": [
{
"national_id": "10102020",
"sponsor_no": "01",
"staff_no": "12",
"name": "Sonya",
"birth_date": "24-2-1999",
"kra_pin": "1111111111",
"employment_date": "10-1-2019",
"employment_type": "temporary",
"email": "email@gmail.com",
"password": "1"
}]
}

我正在尝试使用改造将新数据条目发布给用户受益人等。但是,我似乎无法找出在我的 jsonBinAPI 接口(interface)中描述的正确端点,正如您在我下面发布的代码段中看到的那样。每当我运行应用程序时,都会出现 404 响应代码已记录在我的 logcat 中,并且新记录显然未经过 POST 处理。

主要 Activity

 pojo_user user = new pojo_user(natid,sponsor_no,staff_no,uname,pass);
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://api.jsonbin.io/")
.addConverterFactory(GsonConverterFactory.create())
.build();
jsonBinAPI jsonbinapi = retrofit.create(jsonBinAPI.class);
Call<pojo_user> call = jsonbinapi.setUser(user);
call.enqueue(new Callback<pojo_user>() {
@Override
public void onResponse(Call<pojo_user> call, Response<pojo_user> response) {
Log.v("register_retrofit",Integer.toString(response.code()));
}

@Override
public void onFailure(Call<pojo_user> call, Throwable t) {
Log.v("register_retrofit",t.getMessage());
}
});

pojo_user

public class pojo_user {
private String national_id;
private String sponsor_no;
private String staff_no;
private String name;
private String birth_date;
private String kra_pin;
private String employment_date;
private String employment_type;
private String email;
private String password;
private String log_state;

public pojo_user(String national_id, String sponsor_no, String staff_no, String name, String password) {
this.national_id = national_id;
this.sponsor_no = sponsor_no;
this.staff_no = staff_no;
this.name = name;
this.password = password;
}


}

jsonBinAPI

import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.GET;
import retrofit2.http.POST;


public interface jsonBinAPI {
@GET("b/5e536928d3c2f35597f6ca46/5")
Call<jsonBin_response> getJsonBin_response();
@Headers({"secret-key: <MY_KEY>","Content-Type: application/json","private: false"})
@POST("b/5e536928d3c2f35597f6ca46/5/users")
Call<pojo_user> setUser(@Body pojo_user user);
}

最佳答案

您需要检查他们的 documentation first.

我希望您能从上述所有链接中找到解决问题的线索。

关于java - 如何使用 Retrofit 找到正确的端点以将 JSON 对象 POST 到 JSONbin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60483890/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com