---
title: "Android访问电脑本机"
author: "yaoneng"
date: "2012-02-10T11:20:32Z"
tags: []
categories: ["移动开发"]
slug: "android"
draft: false
lastmod: "2012-02-10T11:20:32Z"
id: 1401723
url: "https://yao.iteye.com/blog/1401723"
---

转载：

 在android开发中， 如果使用localhost 或 127.0.0.1 来访问pc是不对的， 因为Android模拟器（simulator）把它自己作为了localhost,也就是说，代码中使用localhost或者127.0.0.1来访问，都是访问模拟器自己！    如果你想在模拟器上面访问你的电脑，那么就使用android内置的IP 10.0.2.2 吧，10.0.2.2 是模拟器设置的特定ip，是你的电脑的别名alias    记住，在模拟器上用10.0.2.2访问你的电脑本机。