1

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

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

这是我的模型图

在此处输入图像描述

我的 MainActicity 看起来像这样:

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());
        }
    });


}

}
4

1 回答 1

1

弄清楚了。当我将 URL 更改为“服务器”时,我收到了 onSuccess 响应

http://10.0.2.2:3000/api 

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

于 2016-06-13T12:25:24.180 回答