用http連接外部服務

                        String faultSource=bizFaultinfo.getFaultSource();
			if("03".equals(faultSource)||"04".equals(faultSource)){
				
				String telid=null;
				if("03".equals(faultSource)){//電話銀行 
					telid=bizFaultinfo.getN1();
				}
				if("04".equals(faultSource)){//信用卡
					telid=bizFaultinfo.getN2();
				}
				
			
String data="fm_ID:"+telid+";deal_ID:"+person.getPname()+";fault_NO:"+bizFaultinfo.getFaultNo()+ ";deal_Dept:"+person.getAgency().getOrgname()+";deal_Content:"+dealDesc;
				System.out.println(data);
			
				StringBuffer sb = new StringBuffer();
				HttpURLConnection con = null;
				try {
					String urlt="http://192.168.1.150:8088/agent/brilliance/getBusinessYG";
					URL url = new URL(urlt);
					con = (HttpURLConnection) url.openConnection();
					con.setUseCaches(false);
					con.setDoOutput(true);
					con.setRequestMethod("POST");
					con.setRequestProperty("content-type", "application/json;charset=GBK");
				PrintWriter writer = new PrintWriter(new OutputStreamWriter(con.getOutputStream(), "GBK"));
					writer.print(data);
					writer.close();
			BufferedReader reader = new BufferedReader(new InputStreamReader(con.getInputStream(), "GBK"));
					String line = "";
					while (line != null) {
						line = reader.readLine();
						if (line != null) {
							sb.append(line + "\n");
						}
					}
					reader.close();
					con.disconnect();
				} catch (MalformedURLException e) {
					try {
						throw new Exception(e.getMessage());
					} catch (Exception e1) {
						e1.printStackTrace();
					}
				} catch (IOException e) {
					try {
						throw new Exception(e.getMessage());
					} catch (Exception e1) {
						e1.printStackTrace();
					}
				} finally {
					if (con != null) {
						con.disconnect();
					}
				}
				
			}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章