猿问

用http协议建立接连问题,下面是客服端的代码。IP没有错

public void printerInfo() {
   System.out.println("爱的发发达发达的说");

 URL url = null;
   String uslStr = "http://192.168.0.106:8080/manage/typer/save.shtml";
   try {
       url = new URL(uslStr);
       try {
           PrecisionPrint precisionPrint = new PrecisionPrint();
           JSONObject jsonObject = precisionPrint.getPrintMSg();

           URLConnection urlConnection = url.openConnection();
           urlConnection.setRequestProperty("content-type", "application/x-www-form-urlencoded");
           urlConnection.setDoOutput(true);
           urlConnection.setDoInput(true);
           OutputStream out = urlConnection.getOutputStream();
           out.write(jsonObject.toString().getBytes("utf-8"));
           out.flush();
           out.close();

           // 从服务器读取响应
          // InputStream inputStream = urlConnection.getInputStream();
           //String body = IOUtils.toString(inputStream, "utf-8");
           //System.out.println("返回的值是:" + body);


       } catch (Exception e) {
           e.printStackTrace();
       }
   } catch (MalformedURLException e) {
       e.printStackTrace();
   }

}

慕村5072873
浏览 939回答 0
0回答
随时随地看视频慕课网APP

相关分类

Java
我要回答