使用 Loopback Android SDK 访问后端

Accessing backend using Loopback Android SDK

我正在尝试访问使用 Loopback 生成器生成的后端 API。我正在使用内存数据库来存储数据。目前,我正在本地测试它。当我尝试创建 "Feature" 的新实例时,我在回调中收到此错误:

D/AsyncHttpClient: Headers were overwritten! (Accept | application/json) overwrites (Accept | application/json)
V/AsyncHttpResponseHandler: Progress 210 from 210 (100%)
W/remoting.RestAdapter: HTTP request (string) failed: org.apache.http.client.HttpResponseException: Not Found
/xdesign.georgi.espc E/MainActivity: onError - org.apache.http.client.HttpResponseException: Not Found

这是我的模型图

我的 MainActivity 看起来像这样:

public class MainActivity extends AppCompatActivity {

private static final String TAG = MainActivity.class.getSimpleName();
private Model feature;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);







    RestAdapter adapter = new RestAdapter(getApplicationContext(), "http://10.0.2.2:8080/api");

    ModelRepository featureRepository = adapter.createRepository("Feature");
    feature = featureRepository.createObject(ImmutableBiMap.of("name","ANDROID_TEST"));

    feature.save(new VoidCallback() {
        @Override
        public void onSuccess() {
            Log.e(TAG,"onSuccess");
        }

        @Override
        public void onError(Throwable t) {
            Log.e(TAG,"onError - " + t.toString());
        }
    });


}

}

想通了。当我将 URL 更改为 "server" 到

时,我收到了 onSuccess 响应
http://10.0.2.2:3000/api 

显然,我们需要使用端口 3000 才能使其正常工作。