bigzomliao
bigzomliao
  • 发布:2017-10-05 16:51
  • 更新:2022-01-19 00:25
  • 阅读:1233

Android代码如下,请问如何用native.js实现?

分类:HTML5+

请问下android的代码如下,

URL url = new URL(urlStr);

HttpURLConnection con = (HttpURLConnection) url.openConnection();

DataOutputStream dateInput = new DataOutputStream(con.getOutputStream());

InputStream is = con.getInputStream();

用Native.js如何实现。

2017-10-05 16:51 负责人:无 分享
已邀请:
2***@qq.com

2***@qq.com

同问

bianyuan456

bianyuan456

    var surl = "https://www.baidu.com";    
                //var surl = "http://cf.ams.game.qq.com/ams/ame/amesvr?sServiceType=cf&iActivityId=306817";    

                //var aurl = plus.android.newObject("java.net.URL",surl);    
                var URL = plus.android.importClass("java.net.URL");    
                var aurl = new URL(surl);    

                //var con = plus.android.newObject("java.net.HttpURLConnection",aurl.openConnection());    
                var HttpURLConnection = plus.android.importClass("java.net.HttpURLConnection");    
                var con = new HttpURLConnection();    
                con = aurl.openConnection();    
                //plus.android.invoke(con,"setConnectTimeout","300");    
                //plus.android.invoke(con,"setRequestMethod","GET");    
                //plus.android.invoke(con,"connect");    
                con.setConnectTimeout(3000);    
                con.setRequestMethod("GET");    
                //con.setRequestProperty("Content-type", "application/x-www-form-urlencoded");    
                //con.setDoOutput(true);    
                con.connect();    

                var InputStream = plus.android.importClass("java.io.InputStream");    
                var inputstream = new InputStream();    
                var inputstream = con.getInputStream();    
                var BufferedReader = plus.android.importClass("java.io.BufferedReader");    
                var bufferedReader = new BufferedReader();    
                var InputStreamReader = plus.android.importClass("java.io.InputStreamReader");    
                bufferedReader = new InputStreamReader(inputstream, "utf-8");    
                var line="",acceptData="";    

                //line = bufferedReader.readLine();    
                line =plus.android.invoke(bufferedReader,"readLine");    
                while (line != null) { //不为空进行操作    
                    acceptData += line;    
                    //line = bufferedReader.readLine();    
                    line = plus.android.invoke(bufferedReader,"readLine");    

                }    

                console.log(acceptData,line);    
                console.log(con.getResponseCode());//200说明访问成功了

该问题目前已经被锁定, 无法添加新回复