关于后台http请求地址的问题

@Transactional(readOnly = false)
	public IotControlCommandRecord ControlSendJidiPost(IotControlDeviceData iotControlDeviceData, String URL) {

		StringBuilder result = new StringBuilder();
		BufferedReader in = null;
		IotControlCommandRecord iotControlCommandRecord = new IotControlCommandRecord();
		try {
			logger.info(URL);
			iotControlCommandRecord.setMsg("通信中间件连接异常!");
			URL url = new URL(URL);
			// 打开url连接
			HttpURLConnection connection = (HttpURLConnection) url.openConnection();
			// 设置url请求方式 ‘get’ 或者 ‘post’
			connection.setRequestMethod("POST");
			// 发送
			in = new BufferedReader(new InputStreamReader(url.openStream(), "UTF-8"));
			String line = "";
			while ((line = in.readLine()) != null) {
				result.append(line);
			}
			logger.info(result.toString());
			String str = "false";
			if (result.toString().contains(str)) {
				return iotControlCommandRecord;
			} else {
				iotControlCommandRecord.setMsg("控制命令已发送");
				iotControlCommandRecord.setC(iotControlDeviceData.getCtlsn());
				iotControlCommandRecord.setG(iotControlDeviceData.getGatewaysn());
				iotControlCommandRecord.setE(iotControlDeviceData.getDevno());
				// iotControlCommandRecord.setT(Integer.valueOf(iotControlDeviceData.getT() +
				// ""));
				if (iotControlDeviceData.getState()) {
					iotControlCommandRecord.setM("1");
				} else {
					iotControlCommandRecord.setM("0");
				}
				iotControlCommandRecordService.save(iotControlCommandRecord);
			}
		} catch (IOException e) {
			logger.error("URL 异常:" + e.getMessage());
			e.printStackTrace();
		} finally {
			try {
				if (in != null) {
					in.close();
				}
			} catch (IOException e) {
				e.printStackTrace();
				logger.error("关闭流失败" + e.getMessage());
			}
		}
		return iotControlCommandRecord;

	}
public String SetJiDiUrl(CtdDevice ctdDevice, String switchData, Integer slaveId) {
		// "http://222.143.21.116:8085/CTDFishing/mqtt/sendDeviceControlCommand?deviceID=0000010&deviceKey=NJcasyml&msgType=4&msgData.addr="+
		// id + "&msgData.dout="+addr,
		String url = Global.getConfig("JiDiURL") + "sendDeviceControlCommand?deviceID=" + ctdDevice.getDeviceId()
				+ "&deviceKey=" + ctdDevice.getDevicekey() + "&msgType=4&msgData.addr=" + slaveId + "&msgData.dout="
				+ switchData;
		return url;

	}

这是一个发送远程控制命令控制设备的程序,先拼接出来一个字符串url,

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值