【问题标题】:failed request to api Slim frame对 api Slim 框架的请求失败
【发布时间】:2014-08-12 01:17:47
【问题描述】:

我使用来自 http://www.androidhive.info/2014/01/how-to-create-rest-api-for-android-app-using-php-slim-and-mysql-day-23/ 的 Slim 框架构建 web 服务

我检查了 chrome 的 API,一切正常。但我不知道我应该如何在 android 应用程序上使用它。 我尝试这样做:

// Creating HTTP client
HttpClient httpClient = new DefaultHttpClient();
// Creating HTTP Post
HttpPost httpPost = new HttpPost(MY_API_URL);

// Building post parameters
// key and value pair
List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(3);
nameValuePair.add(new BasicNameValuePair("name", "Name_"));
                        nameValuePair.add(new BasicNameValuePair("email", "email@email.com"));
nameValuePair.add(new BasicNameValuePair("password", "pass"));
// Url Encoding the POST parameters
try {
   httpPost.setEntity(new UrlEncodedFormEntity(nameValuePair));
} catch (UnsupportedEncodingException e) {
// writing error to Log
e.printStackTrace();
}

// Making HTTP Request
try {
   HttpResponse response = httpClient.execute(httpPost);

// writing response to log
   Log.d("Http Response:", response.toString());
} catch (ClientProtocolException e) {
// writing exception to log
e.printStackTrace();
} catch (IOException e) {
// writing exception to log
   e.printStackTrace();
}

怎么了?

【问题讨论】:

    标签: android mysql api slim


    【解决方案1】:

    我会使用retrofit 而不是DefaultHTTPClient

    【讨论】:

      猜你喜欢
      • 2017-03-26
      • 1970-01-01
      • 2015-10-24
      • 1970-01-01
      • 1970-01-01
      • 2019-10-04
      • 2014-05-02
      • 2017-10-15
      • 2013-06-12
      相关资源
      最近更新 更多