android-emulator - 在服务器上,Android 应用 无法连接到主机名,但可以连接到 IP

  显示原文与译文双语对照的内容
0 0

我的Android 应用 有一个奇怪的问题。 我可以在硬编码服务器地址时连接和发送数据,但我尝试使用主机名时得到错误。 我已经在 Windows Server 2003的模拟器 上通过进行了测试。 我还确保地址以http开头,应用程序使用internet的权限。 关于这一切的任何想法? 在使用 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

POST


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();
 }

 }

时间: 原作者:

0 0

我的问题是与我公司的特殊权限,我不理解。 我无法使用我的应用来连接,因为安全考虑。 但是,如果其他人遇到与( 我只是想承载一个PHP脚本来使用 POST ) 相同的问题,请使用 Google App Engine 。 我一直在用它,这是我一直在寻找的东西。 https://appengine.google.com/

原作者:
...