用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();
}
} |
免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。
版权声明:作者保留权利,不代表天盟立场。
|
|
|
|