我想在Java中使用具有基本身份验证(用户名,密码)的代理进行连接(并且只有此连接).以下代码适用于HTTP URL(例如" http://www.google.com "):
URL url = new URL("http://www.google.com");
HttpURLConnection httpURLConnection = null;
InetSocketAddress proxyLocation = new InetSocketAddress(proxyHost, proxyPort);
Proxy proxy = new Proxy(Proxy.Type.HTTP, proxyLocation);
httpURLConnection = (HttpURLConnection) url.openConnection(proxy);
// Works for HTTP only! Doesn't work for HTTPS!
String encoded = new sun.misc.BASE64Encoder().encodeBuffer((proxyUserName + ":" + proxyPassword).getBytes()).replace("\r\n", "");
httpURLConnection.setRequestProperty("Proxy-Authorization", "Basic " + encoded);
InputStream is = httpURLConnection.getInputStream();
InputStreamReader isr = new InputStreamReader(is); 
int data = isr.read();
while(data != -1){
  char c = (char) data;
  data = isr.read();
  System.out.print(c);
}
isr.close(); …我试图在Ubuntu Jaunty中使用nginx进行基本身份验证.在nginx.conf中,我在服务器上下文中添加了这两行:
server {
   ...
   auth_basic "Restricted Access";
   auth_basic_user_file /etc/nginx/.htpasswd;
   ...
}
然后我apt-get'ed apache2-utils获取htpasswd,我用它来创建htpasswd文件:
htpasswd -d -c /etc/nginx/.htpasswd joe
当我尝试访问该站点时,验证对话框按预期出现,但是当我输入用户名和密码时,它只刷新了对话框.它似乎不喜欢我提供它的密码.我尝试使用和不使用-d选项运行htpasswd,但仍然没有运气.它拒绝进行身份验证.我有什么想法我做错了吗?
任何帮助,将不胜感激.
我知道通常你可以通过在URL中传递用户名和密码来登录需要使用Selenium进行HTTP基本身份验证的站点,例如:
selenium.open("http://myusername:myuserpassword@mydomain.com/mypath");
我一直在使用Firefox 2或3运行Selenium测试,在那里我仍然得到"需要身份验证"对话框窗口?
更新:似乎不是Selenium问题,而是Firefox问题.如果我在FF中手动输入URL,我将获得身份验证对话框,但如果我在Opera中输入URL,则会显示我的页面而不显示身份验证对话框.
当我使用HTTP BASIC身份验证和HTTPS时,用户名和密码是否安全地传递给服务器?
如果你能帮助我一些参考资料,我会很高兴的.
我的意思是,如果我能将StackOverflow问答作为参考,比如作业,报告,考试甚至是技术论文,那就太棒了.但我想我还没有.
我确定我在这里做错了,但这就是我的应用程序控制器的样子:
class ApplicationController < ActionController::API                                                                                                                                                                                                        
  include ActionController::HttpAuthentication::Basic                                                                                                                                                                                                      
  include ActionController::MimeResponds                                                                                                                                                                                                                   
  http_basic_authenticate_with :name => "joeyjojo", :password => "shabadoo"
end
我无法弄清楚为什么我的http_basic_authenticate_with会抛出此错误:
undefined method `http_basic_authenticate_with' for ApplicationController:Class
我确定这很简单,但我没有看到它.MimeResponds在其他控制器中工作得很好.
这可能是一个愚蠢的问题,但我可以安全地使用基本的HTTP身份验证,或者即使服务器已经在SSL上,我仍然可以从摘要身份验证中受益吗?
authentication ssl https basic-authentication digest-authentication
看了很多之后,我发现了一些似乎有效的解决方案,但对我来说并不适用......
例如,我有这个脚本:
require 'net/http'
require "net/https"
@http=Net::HTTP.new('www.xxxxxxx.net', 443)
@http.use_ssl = true
@http.verify_mode = OpenSSL::SSL::VERIFY_NONE
@http.start() {|http|
    req = Net::HTTP::Get.new('/gb/PastSetupsXLS.asp?SR=31,6')
    req.basic_auth 'my_user', 'my_password'
    response = http.request(req)
    print response.body
}
当我运行它时,它会给我一个请求身份验证的页面,但是如果我在浏览器中编写以下URL,我会毫无问题地进入网站:
https://my_user:my_password@www.xxxxxxx.net/gb/PastSetupsXLS.asp?SR=31,6
我也试过open-uri:
module OpenSSL
    module SSL
        remove_const :VERIFY_PEER
    end
end
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
def download(full_url, to_here)
    writeOut = open(to_here, "wb") 
    writeOut.write(open(full_url, :http_basic_authentication=>["my_user", "my_password"]).read) 
    writeOut.close 
end
download('https://www.xxxxxxx.net/gb/PastSetupsXLS.asp?SR=31,6', "target_file.html")
但结果是一样的,该网站要求用户身份验证.我做错了什么提示?我必须在Base 64中编码密码吗?
我开始研究Web Api,只想创建一个简单的基本身份验证.我想知道怎么做?
我尝试使用给定的MSDN链接,但在MSDN上没有给出逐步教程. http://www.asp.net/web-api/overview/security/basic-authentication
我目前正致力于将第三方应用程序与我们的本地报告系统集成.我想用基本身份验证实现REST调用,但在Spring 4.0.0中遇到问题.我有一个简单的解决方案,它很有效:
final RestTemplate restTemplate = new RestTemplate();
final String plainCreds = "username:password";
final byte[] plainCredsBytes = plainCreds.getBytes();
final byte[] base64CredsBytes = Base64.encodeBase64(plainCredsBytes);
final String base64Creds = new String(base64CredsBytes);
final HttpHeaders headers = new HttpHeaders();
headers.add("Authorization", "Basic " + base64Creds);
final HttpEntity<String> request = new HttpEntity<String>(headers);
final ResponseEntity<MyDto> response = restTemplate.exchange("myUrl", HttpMethod.GET, request, MyDto.class);
final MyDto dot = response.getBody();
但是想通过以下方式重写这个以使用ClientHttpRequestFactory:
final RestTemplate restTemplate = new RestTemplate(createSecureTransport("username", "password"));
private ClientHttpRequestFactory createSecureTransport(final String username, final String password) {
    final HttpClient …我们碰巧运行带有API的REST Web服务,要求客户端使用基本身份验证.我们用各种语言制作了一套简洁的样本,展示了如何与我们的服务进行交互.现在我正在检查服务的IIS日志,并发现以下模式经常发生:
看起来像第一个请求没有授权标头发送,然后第二个请求与正确的标头一起发送并成功.大多数情况下,日志记录包含"user-agent",这与我们在.NET示例中植入的字符串相同.
所以我认为问题仅在于.NET程序.我们的示例代码没有重现该问题,因此我假设用户以某种方式修改了代码或从头开始编写自己的代码.
我们尝试联系用户,但显然他们不想花时间研究.所以很高兴找到导致.NET程序这种行为的最可能的情况.
他们为什么要这样做?他们为什么不在第一次尝试时附上标题?