Commit c6d457b82666dc5bac722ac648d237bb6b2ad22b
1 parent
6cf6747a
DataOutputStream改为OutputStreamWriter
Showing
3 changed files
with
23 additions
and
9 deletions
src/main/java/com/huaheng/api/mes/domain/LoginMES.java
src/main/java/com/huaheng/api/mes/service/MESHelper.java
... | ... | @@ -2,15 +2,15 @@ package com.huaheng.api.mes.service; |
2 | 2 | |
3 | 3 | import com.alibaba.fastjson.JSONObject; |
4 | 4 | import com.huaheng.api.mes.domain.MESUri; |
5 | +import com.huaheng.common.utils.http.HttpUtils; | |
5 | 6 | import com.huaheng.framework.aspectj.ApiLogAspect; |
7 | +import com.huaheng.framework.web.domain.AjaxResult; | |
6 | 8 | import com.huaheng.pc.monitor.apilog.domain.ApiLog; |
7 | 9 | import com.huaheng.pc.system.config.service.IConfigService; |
8 | 10 | import org.springframework.beans.factory.annotation.Autowired; |
9 | 11 | import org.springframework.stereotype.Service; |
10 | 12 | |
11 | -import java.io.BufferedReader; | |
12 | -import java.io.DataOutputStream; | |
13 | -import java.io.InputStreamReader; | |
13 | +import java.io.*; | |
14 | 14 | import java.net.HttpURLConnection; |
15 | 15 | import java.net.URL; |
16 | 16 | |
... | ... | @@ -27,7 +27,6 @@ public class MESHelper { |
27 | 27 | HttpURLConnection connection = (HttpURLConnection) postUrl |
28 | 28 | .openConnection(); |
29 | 29 | String MESCookie = configService.selectConfigByKey("MESCookie"); |
30 | - connection.setRequestProperty("Authorization", MESCookie); | |
31 | 30 | connection.setDoOutput(true); |
32 | 31 | connection.setDoInput(true); |
33 | 32 | connection.setUseCaches(false); |
... | ... | @@ -35,9 +34,13 @@ public class MESHelper { |
35 | 34 | connection.setRequestMethod("POST");// 设置请求方式 |
36 | 35 | connection.setRequestProperty("Accept","application/json");// 设置接收数据的格式 |
37 | 36 | connection.setRequestProperty("Content-Type","application/json");// 设置发送数据的格式 |
37 | + connection.setRequestProperty("Authorization", MESCookie); | |
38 | 38 | apiLog = ApiLogAspect.initApiLog(connection, paras, "MES"); |
39 | - DataOutputStream out = new DataOutputStream(connection.getOutputStream()); | |
40 | - out.writeBytes(paras); | |
39 | +// DataOutputStream out = new DataOutputStream(connection.getOutputStream()); | |
40 | + // out.writeBytes(paras); | |
41 | + OutputStreamWriter out = null; | |
42 | + out = new OutputStreamWriter(connection.getOutputStream(),"UTF-8");// utf-8编码 | |
43 | + out.append(paras); | |
41 | 44 | out.flush(); |
42 | 45 | out.close(); |
43 | 46 | return connection; |
... | ... | @@ -45,7 +48,17 @@ public class MESHelper { |
45 | 48 | |
46 | 49 | public void insertAgvPort(String param) throws Exception { |
47 | 50 | HttpURLConnection connection = initUrlConn(MESUri.INSERT_AGV_PORT.getApiUri(), param); |
51 | + BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); | |
52 | + String line; | |
53 | + String sResult=null; | |
54 | + while ((line = reader.readLine()) != null) { | |
55 | + sResult = new String(line.getBytes(), "UTF-8"); | |
56 | + System.out.println(sResult); | |
57 | + } | |
58 | + reader.close(); | |
48 | 59 | connection.disconnect(); |
60 | + ApiLogAspect.finishApiLog(apiLog,connection, AjaxResult.success(sResult).toString()); | |
61 | +// HttpUtils.bodypost(MESUri.INSERT_AGV_PORT.getApiUri(),param,"CS0001"); | |
49 | 62 | } |
50 | 63 | |
51 | 64 | public JSONObject returnOrderCode(String param) throws Exception { |
... | ... |
src/main/java/com/huaheng/pc/monitor/job/task/RyTask.java
... | ... | @@ -405,11 +405,12 @@ public class RyTask extends BaseController { |
405 | 405 | |
406 | 406 | public void loginMES(String params) |
407 | 407 | throws Exception { |
408 | - System.out.println("params:" + params); | |
409 | 408 | LoginMES loginMES = JSON.parseObject(params, LoginMES.class); |
409 | + HashMap map=new HashMap(); | |
410 | + map.put("body",loginMES); | |
410 | 411 | String sUrl = MESUri.LOGIN.getApiUri(); |
411 | 412 | Gson gson = new Gson(); |
412 | - String s = gson.toJson(loginMES); | |
413 | + String s = gson.toJson(map); | |
413 | 414 | HttpURLConnection connection = mesHelper.initUrlConn(sUrl, s); |
414 | 415 | // 获取Cookie |
415 | 416 | BufferedReader reader = new BufferedReader(new InputStreamReader( |
... | ... |