j***@163.com
j***@163.com
  • 发布:2019-04-26 10:33
  • 更新:2021-05-26 17:03
  • 阅读:1563

native.js 连接wifi 打印机。 可以连接上但是返回 msg 400 Bad Request

分类:Native.js

connect3('123123', '192.168.0.122', 80);
function connect3(str, ip, port) {
if (plus.os.name == "Android") {
var Socket = plus.android.importClass("java.net.Socket");
var PrintWriter = plus.android.importClass("java.io.PrintWriter");
var BufferedWriter = plus.android.importClass("java.io.BufferedWriter");
var OutputStreamWriter = plus.android.importClass("java.io.OutputStreamWriter");
var BufferedReader = plus.android.importClass("java.io.BufferedReader");
var InputStreamReader = plus.android.importClass("java.io.InputStreamReader");

                //测试改良    
                var StrictMode = plus.android.importClass("android.os.StrictMode");    
                var Build = plus.android.importClass("android.os.Build");    
                if (Build.VERSION.SDK_INT > 9) {    
                    var policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();    
                    StrictMode.setThreadPolicy(policy);    
                }    
                var socket = new Socket(ip, port);  

                var outputStreamWriter = new OutputStreamWriter(socket.getOutputStream());  
                var bufferWriter = new BufferedWriter(outputStreamWriter);  
                var out = new PrintWriter(bufferWriter, true);  
                out.println(str);  

                var inputStreamReader = new InputStreamReader(socket.getInputStream());  
                var br = new BufferedReader(inputStreamReader);  
                var msg = br.readLine();  

                //while(true)    
                {  
                    if (msg != null) {  
                        console.log(msg);  
                    }  
                    //msg = br.readLine();          
                }  
            }  
            //console.log(mac);    
            alert("Done");  

        }
2019-04-26 10:33 负责人:无 分享
已邀请:
2***@qq.com

2***@qq.com

楼主解决问题了吗?我碰到了一个需要用wifi连接打印机的需求,有点搞不懂

  • ssyi

    你好,请问uniapp安卓连接Wi-Fi打印机还在做吗,我现在卡在指令上面了,希望能借鉴下您的经验。非常感谢

    2023-01-11 10:09

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