我写了一个wcf服务应用程序,想要从Android应用程序访问它。
当我使用android studio模拟器时,我用localhost
替换了URL中的10.0.2.2
。
现在我在win 8.1 pc中使用windroye模拟器。我应该使用什么网址?
public static String connect(String json) {
String url="http://10.0.2.2:1755/service1.svc/func";
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
StringEntity se = null;
try {
se = new StringEntity(json);
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
httppost.setEntity(se);
httppost.setHeader("Accept", "application/json");
httppost.setHeader("Content-type", "application/json");
String result = "";
HttpResponse response;
try {
response = httpclient.execute(httppost);
// Examine the response status
Log.i("Praeda", response.getStatusLine().toString());
// Get hold of the response entity
HttpEntity entity = response.getEntity();
result = EntityUtils.toString(entity);
} catch (Exception e) {
}
return result;
}