安卓HTTPGET问题 [英] android httpGet issue

查看:140
本文介绍了安卓HTTPGET问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想执行下面的链接使用下列code:

I am trying to execute the following link using following code:

class httpget{
HttpGet httpGet=null;

public void linkexecute(){
String url="http://<server>/<path>/action=send&msg=new message";
httpGet= new HttpGet(url); // line 1
....
}

at line 1 it is giving error "Illegal arguement exception"    
java.lang.IllegalArgumentException: Illegal character in query at index 77: http://<server>/<path>/sms.json?action=send&msg=new message    
at java.net.URI.create(URI.java:970)    
at org.apache.http.client.methods.HttpGet.<init>(HttpGet.java:75)    
at com.sms.login.LoginService.sendSms(LoginService.java:143)

虽然有有没有间隙的话没有错误的下面给出的URL味精=

Whereas there's no error for given below URL which has no gaps in words of "msg="

String url="http://<server>/<path>/action=send&msg=newmessage";

我怎样才能在URL解决的话差距问题?

How can I resolve the issue of gap in words in URL?

推荐答案

在这里,我给你一个功能,将删除所有无效字符的URL。请把您的网址在此功能,您将获得一个新的URL与EN codeD字符串。

Here, i give you one function that will remove all invalid characters from the url . Please pass your url in this function and you will get a new url with encoded strings.

public static String convertURL(String str) {

    String url = null;
    try{
    url = new String(str.trim().replace(" ", "%20").replace("&", "%26")
            .replace(",", "%2c").replace("(", "%28").replace(")", "%29")
            .replace("!", "%21").replace("=", "%3D").replace("<", "%3C")
            .replace(">", "%3E").replace("#", "%23").replace("$", "%24")
            .replace("'", "%27").replace("*", "%2A").replace("-", "%2D")
            .replace(".", "%2E").replace("/", "%2F").replace(":", "%3A")
            .replace(";", "%3B").replace("?", "%3F").replace("@", "%40")
            .replace("[", "%5B").replace("\\", "%5C").replace("]", "%5D")
            .replace("_", "%5F").replace("`", "%60").replace("{", "%7B")
            .replace("|", "%7C").replace("}", "%7D"));
    }catch(Exception e){
        e.printStackTrace();
    }
    return url;
}

这篇关于安卓HTTPGET问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆