我的Android应用程序出现了一个奇怪的问题。我在硬编码服务器的IP地址时可以连接和发送数据,但是当我尝试使用主机名时,我会收到以下错误。我一直在Windows服务器2003上通过android的模拟器测试这个。我还确保地址以http开头并且应用程序使用了互联网的许可。关于为什么会这样的任何想法? E.G我可以在使用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
发布
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/