代码:
String urlAPI = "http://www.domain.com/api.php?msg="+msg+"&mobile="+mobile;
URL url = new URL(urlAPI); HttpURLConnection connection = (HttpURLConnection)url.openConnection(); connection.setRequestMethod("GET");
connection.connect();
BufferedReader bf = new BufferedReader( new InputStreamReader(connection.getInputStream()));
String value = bf.readLine();
System.out.println("Result "+value);
logcat的:
08-13 10:58:45.851 10075-10075/com.example.cyb3rx.smsjungle I/dalvikvm-heap: Grow heap (frag case) to 3.188MB for 281892-byte allocation
08-13 10:58:45.861 10075-10084/com.example.cyb3rx.smsjungle D/dalvikvm: GC_FOR_ALLOC freed 1K, 20% free 3234K/4008K, paused 8ms, total 8ms
08-13 10:58:45.871 10075-10972/com.example.cyb3rx.smsjungle W/System.err: java.net.MalformedURLException: Protocol not found:
答案 0 :(得分:0)
查询字符串由一系列字段 - 值对组成。内 每对,字段名称和值用等号分隔, ' =&#39 ;.这对系列由&符号分隔,''
尝试改为
String urlAPI = "http://www.domain.com/api.php?msg="+msg+"&mobile="+mobile;
答案 1 :(得分:0)
尝试编码查询参数:
URLEncoder.encode(“msg =”+ msg +“& mobile =”+ mobile,“UTF-8”);
所以您的网址为http://www.domain.com/api.php?msg%3D%20Hello%26mobile%3D%201234567890