在Android手机上调试程序时,由于没有数据线,就建立了一个无线局域网和本机服务器做离线调试。
需要打印日志的地方调用WL.log("key","value");即可
- public class WL {
- static String url = "http://10.12.11.54:8080/log/p_w_picpathLog";
- public static void Log(String key ,String value){
- HttpURLConnection con =null;
- try {
- URL uri = new URL(url+"?"+key+"="+value);
- con = (HttpURLConnection) uri.openConnection();
- con.setRequestMethod("POST");
- con.getResponseCode();
- } catch (MalformedURLException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
另服务端的几行代码:
- protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- try{
- Enumeration<String> enu = request.getParameterNames();
- while(enu.hasMoreElements()){
- String logName = enu.nextElement().toString();
- System.out.println("Time:"+ new Date().toLocaleString()+" "+logName+" :"+request.getParameter(logName));
- }
- }catch (Exception e) {
- e.printStackTrace();
- }
- }