我正在尝试从 android 发布到 GAE,我遇到了未知的主机异常。这是我的代码,
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://silver-kites.appspot.com");
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("abc", "123"));
nameValuePairs.add(new BasicNameValuePair("xyz", "456"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
if(entity != null){
InputStream inputStream = entity.getContent();
ResponseText.setText(convertStreamToString(inputStream));
}
} catch (ClientProtocolException e) {
ResponseText.setText(e.getMessage());
} catch (IOException e) {
ResponseText.setText(e.getMessage());
}
当我尝试连接到 localhost:8888 时,连接被拒绝。我不知道如何通过这个。帮助我。
最佳答案
我也试过了,在 android 中仍然出现未知主机异常。是否需要做任何设置才能访问 HTTP?或者在模拟器中 http 将无法工作?
我设置了 <uses-permission android:name="android.permission.INTERNET"></uses-permission>
在 android list xml 中。仍然没有希望。
有帮助吗?我 checkin 了 GAE,但我的请求没有到达那里。
这是我的代码,
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://silver-kites.appspot.com/silverscores");
try {
nameValuePairs.add(new BasicNameValuePair("name", "JP"));
nameValuePairs.add(new BasicNameValuePair("seconds", "123"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
if(entity != null){
InputStream inputStream = entity.getContent();
ResponseText.setText(convertStreamToString(inputStream));
}
} catch (ClientProtocolException e) {
ResponseText.setText(e.getMessage());
} catch (IOException e) {
ResponseText.setText(e.getMessage());
}
关于android - 从android到GAE的未知主机异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3544557/