Android应用程序无法连接到主机名,但可以连接到服务器上的IP

Android应用程序无法连接到主机名,但可以连接到服务器上的IP,android,android-emulator,hostname,windows-server,Android,Android Emulator,Hostname,Windows Server,我的android应用程序有一个奇怪的问题。我可以在硬编码服务器的IP地址时连接和发送数据,但在尝试使用主机名时会出现以下错误。我已经在WindowsServer2003上通过android的模拟器进行了测试。我还确保地址以http开头,并且应用程序使用互联网的权限。你知道为什么会这样吗?例如,当我使用123.45.678/test.php但不使用servername/test.php时,我可以连接 06-12 17:02:30.360: I/Choreographer(642): Skippe

我的android应用程序有一个奇怪的问题。我可以在硬编码服务器的IP地址时连接和发送数据,但在尝试使用主机名时会出现以下错误。我已经在WindowsServer2003上通过android的模拟器进行了测试。我还确保地址以http开头,并且应用程序使用互联网的权限。你知道为什么会这样吗?例如,当我使用123.45.678/test.php但不使用servername/test.php时,我可以连接

06-12 17:02:30.360: I/Choreographer(642): Skipped 31 frames!  The application may be doing too much work on its main thread.
06-12 17:03:07.670: I/Choreographer(642): Skipped 85 frames!  The application may be doing too much work on its main thread.
06-12 17:03:07.810: I/Choreographer(642): Skipped 36 frames!  The application may be doing too much work on its main thread.
06-12 17:03:16.200: W/System.err(642): java.net.UnknownHostException: Unable to resolve host "HOSTNAME": No address associated with hostname
职位


我的问题是我不了解公司的特殊权限。出于安全考虑,我无法使用我的应用程序进行连接。但是,如果其他人遇到与我相同的问题,我只想托管一个PHP脚本来使用POST,使用Google App Engine。我现在一直在使用它,这是我一直在寻找的一切。

您的服务器正在运行吗?@Rod_Algonquin是的,我在服务器上启用了PHP,可以通过浏览器进行任意连接。您是否尝试过通过任何其他设备(如PC)连接到该主机?你的主机真的叫主机名吗@nyarlathotep77是的,我可以连接多台电脑。哈哈,不,主机名只是一个占位符。可以看看你是如何在Android应用程序中连接到你的主机的吗?
public void postData(String Filename) {
                // Create a new HttpClient and Post Header
                HttpClient httpclient = new DefaultHttpClient();
                if (!MainActivity.address.startsWith("https://") && !MainActivity.address.startsWith("http://")){
                    MainActivity.address = "http://" + MainActivity.address;
                }
                HttpPost httppost = new HttpPost(MainActivity.address);
                HttpResponse response = null;
                try {
                    // Add your data
                    //MainActivity.QRdata.replaceAll("\\s+","");
                    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
                    nameValuePairs.add(new BasicNameValuePair("data", "<data><serial><serial>SN001</serial></serial><items><item>Test1 = Failed</item><item>Test2 = Passed</item><item>Test3 = Passed</item></items></data>"));
                    nameValuePairs.add(new BasicNameValuePair("file", Filename));
                    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

                    // Execute HTTP Post Request
                    response = httpclient.execute(httppost);
                    String res = EntityUtils.toString(response.getEntity());
                    Log.v("Response = ", res);

                } catch (ClientProtocolException e) {
                    e.printStackTrace();
                    // TODO Auto-generated catch block
                } catch (IOException e) {
                    e.printStackTrace();
                    // TODO Auto-generated catch block
                }
                //return response.toString();
            }

        }