使用代理的Java中的HTTP基本身份验证
我正在尝试使用HTTPPOST将文件发送到需要基本身份验证的web服务器 MyWorkplace最近对代理服务器进行了更改,现在还需要基本身份验证使用代理的Java中的HTTP基本身份验证,java,http,proxy,http-headers,basic-authentication,Java,Http,Proxy,Http Headers,Basic Authentication,我正在尝试使用HTTPPOST将文件发送到需要基本身份验证的web服务器 MyWorkplace最近对代理服务器进行了更改,现在还需要基本身份验证 如何在一个HttpPost请求中输入这两个服务器的凭据?您需要在以下行中添加http标头,如中所述: 用户名和密码由一个冒号组合而成 生成的字符串使用的RFC2045-MIME变量进行编码 Base64,但不限于76个字符/行 然后将授权方法和空格(即“Basic”)放在编码字符串之前 请看Apache HttpClient的示例: String
如何在一个HttpPost请求中输入这两个服务器的凭据?您需要在以下行中添加http标头,如中所述:
请看Apache HttpClient的示例:
String encoding = Base64Encoder.encode ("your_login:your_password");
HttpPost httppost = new HttpPost("http://host:post/test/login");
httppost.setHeader("Authorization", "Basic " + encoding);
System.out.println("executing request " + httppost.getRequestLine());
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
原来我还需要添加一个“代理授权”标题
HttpPost httpPost = new HttpPost("http://host:port/test/login");
String encoding = Base64Encoder.encode ("your_user:your_password");
httpPost.setHeader("Authorization", "Basic " + encoding);
String proxyEncoding = Base64Encoder.encode ("proxy_user:proxy_password");
httpPost.setHeader("Proxy-Authorization", "Basic " + proxyEncoding);
System.out.println("executing request " + httpPost.getRequestLine());
HttpResponse response = httpClient.execute(httpPost);
因此,登录名和密码是针对web服务器的。代理服务器的用户名和密码是什么?