Address family not supported by protocol family

public static void main(String[] args) throws Exception {
		//http://mis.****.cn/api/delivery/insInfo?SRCID=hzhdyyjtgs&busidata={"timeStamp":"2017-01-01 11:18:15"}&sign=c7b2da0c86b121c65803104e07ee04ff
		String url = "http://mis.drugcloud.cn/api/delivery/";
		String interfaceName = "insInfo";
		url = url+interfaceName;
		String data = "SRCID=hzhdyyjtgs&busidata={\"timeStamp\":\"2017-01-01 11:18:15\"}&sign=c7b2da0c86b121c65803104e07ee04ff"; 
		sendPostUrl(url, data);
		
		
}

public static JSONObject sendPostUrl(String url, String param) {
		PrintWriter out = null;
		BufferedReader in = null;
		JSONObject jsonObject = null;
		StringBuffer result = new StringBuffer();
		try {
			URL realUrl = new URL(url);
			URLConnection conn = realUrl.openConnection();
			conn.setDoOutput(true);
			conn.setDoInput(true);
			out = new PrintWriter(new OutputStreamWriter(conn.getOutputStream(), "UTF-8"));
			out.print(param);
			out.flush();
			in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
			String line;
			while ((line = in.readLine()) != null) {
				result.append(line);
			}
			jsonObject = JSONObject.fromObject(result.toString());
			JSONArray goodsArr = jsonObject.getJSONArray("data");
			for(int i = 0;i < goodsArr.size();i++){
				JSONObject goodsInfo = goodsArr.getJSONObject(i);
				System.out.println(goodsInfo);
			}
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				if (out != null) {
					out.close();
				}
				if (in != null) {
					in.close();
				}
			} catch (IOException ex) {
				ex.printStackTrace();
			}
		}
		return jsonObject;
	}

同样的方法,放到工程中,调用接口异常,返回java.io.socketException:Address family not supported by protocol family

 

发布了49 篇原创文章 · 获赞 16 · 访问量 6万+

猜你喜欢

转载自blog.csdn.net/qq_26929957/article/details/95166069
今日推荐