0

Web サービスへの投稿で実際に問題が発生しています。問題は URL にあるようです。サブドメインにハイフンが含まれています。以下の URL は実際のものではありませんが、お分かりになるはずです。

ハイフンを含む URL を渡すと、次のエラーが発生します。

02-27 10:33:45.992: E/AndroidRuntime(2226): java.lang.IllegalArgumentException: ホスト名が null でない可能性があります

ハイフンが省略されている場合は、少なくとも 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();
    }
4

1 に答える 1

1

無効な文字を自動的にエスケープするURI コンストラクターを使用できます。

URL url = new URI("http", "//mbhh.one-dev.co.uk/HandsetService.asmx?op=Opp", null).toURL();
于 2012-02-27T11:11:50.697 に答える