Android 发布包含下划线的url(\ux)

Android 发布包含下划线的url(\ux),android,Android,我正在发布一个url,其参数包含下划线(\ux) 示例:http://sdsdsds_asasasahjhd.com/dsdsdsd/login.json? 我是这样发布的: HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://sdsdsds_asasasahjhd.com/dsdsdsd/login.json?"); try {

我正在发布一个url,其参数包含下划线(\ux)

示例:
http://sdsdsds_asasasahjhd.com/dsdsdsd/login.json?

我是这样发布的:

    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("http://sdsdsds_asasasahjhd.com/dsdsdsd/login.json?");
    try {
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
        nameValuePairs.add(new BasicNameValuePair("key1", "value1"));
        nameValuePairs.add(new BasicNameValuePair("key2", "value2"));
        nameValuePairs
                .add(new BasicNameValuePair("key3", "value3"));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        // Execute HTTP Post Request
        HttpResponse response = httpclient.execute(httppost);

    } catch (Exception e) {
        e.printStackTrace();
    }
HttpClient-HttpClient=newdefaulthttpclient();
HttpPost HttpPost=新的HttpPost(“http://sdsdsds_asasasahjhd.com/dsdsdsd/login.json?");
试一试{
List nameValuePairs=新的ArrayList(2);
添加(新的BasicNameValuePair(“键1”、“值1”);
添加(新的BasicNameValuePair(“键2”、“值2”);
nameValuePairs
.添加(新的BasicNameValuePair(“键3”、“值3”);
setEntity(新的UrlEncodedFormEntity(nameValuePairs));
//执行HTTP Post请求
HttpResponse response=httpclient.execute(httppost);
}捕获(例外e){
e、 printStackTrace();
}
当我检查
httpclient.execute(httppost)
时,我得到了
IllegalArgumentException
,在catch in exception details中,它告诉我
主机名不能为null
。 请指定任何解决方案

我在这里讨论了一些其他问题:


但是没有用,因为我没有对整个url进行编码。

它清楚地表明主机名不能为空。。您的url没有指定一个

url的格式应为

http://hostName.com/example..../example.json

HttpPost-HttpPost=新的HttpPost(字符串)

此构造函数将尝试从提供的字符串形成实例。如果失败,您将处理一个
null


如果您希望我们能够进一步帮助您,请发布您正在使用的实际URL,而不是示例。

我有一个带有网络实现机制的开源库。它只是一个解决方案实现。发生故障时,通过反射设置主机所需的一切:

        final URI uriObj = new URI("https", host, path, null, null);
        if (uriObj.getHost() == null) {
            final Field hostField = URI.class.getDeclaredField("host");
            hostField.setAccessible(true);
            hostField.set(uriObj, host);
        }
        return uriObj;

提交是。

请参阅此链接。Apache不支持下划线。您应该更改url


主机名不能包含下划线…如果您提供(部分)的堆栈跟踪和有关发生异常的行号的详细信息。@Veger我已经编辑了问题。@Selvin但是相同的url在Iphone中工作。检查RFC 952和RFC 1123…相同的url在Iphone中工作,那么我认为它应该在android中工作。这是错误的。实际上,URI类不支持带有下划线的主机名,但我正在搜索解决方法(-1)抱歉,无法发布实际的url。你认为这一切都是因为“u”?不,下划线不是问题所在,它是url的格式,它看起来不像url,它必须在某个地方有tld。