我在发布到 Web 服务时遇到了真正的问题,似乎问题出在 url 上——子域中有一个连字符。下面的 URL 不是真实的,但您应该明白这一点。
传递带有连字符的 URL 时出现此错误:
02-27 10:33:45.992: E/AndroidRuntime(2226): java.lang.IllegalArgumentException: 主机名不能为空
如果连字符被省略,那么至少它会查找 URL。
请帮忙!
HttpClient httpclient = new DefaultHttpClient();
try {
HttpPost httppost = new HttpPost("http://mbhh.one-dev.co.uk/HandsetService.asmx?op=Opp");
StringEntity se = new StringEntity( getUploadXml ().toString(), HTTP.UTF_8);
se.setContentType("text/xml");
httppost.setEntity(se);
HttpResponse httpresponse = httpclient.execute(httppost);
HttpEntity resEntity = httpresponse.getEntity();
String result = EntityUtils.toString(resEntity);
Log.d(TAG, "writer = "+result);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}