if(!isset($_SERVER['PHP_AUTH_USER']) && !isset($_SERVER['PHP_AUTH_PW'])){ Header("WWW-Authenticate: Basic realm=\"USER LOGIN\""); Header("HTTP/1.0 401 Unauthorized"); } else { echo $_SERVER['PHP_AUTH_USER']; echo $_SERVER['PHP_AUTH_PW']; }
--------------------------------------
http://tool.chinaz.com/Tools/Base64.aspx
比如java的http请求认证:
Base64加密码:Z3Vlc3Q6Z3Vlc3Q=
表示:guest:guest
HttpGet httpGet = new HttpGet("http://192.168.1.10:55672/api/queues"); httpGet.setHeader("Authorization", "Basic Z3Vlc3Q6Z3Vlc3Q="); try { HttpResponse httpResponse = httpClient.execute(httpGet); String res = EntityUtils.toString(httpResponse.getEntity()); } catch (Exception e) { LOGGER.warn("http client fail", e); return null; }