我完全迷失了。我尝试使用HTTP Basic Auth验证Tomcat 7.0.54以获取资源。
我尝试连接的第一天我得到401.剩下的时间我将获得资源。即使我重新启动Tomcat,我也将获得第一个请求的资源。我无法重启客户端......
我有以下代码:
URL urlObject = new URL(url);
String userPassword = username + ":" + password;
String encoding = new sun.misc.BASE64Encoder().encode(userPassword.getBytes());
HttpURLConnection connection = (HttpURLConnection) urlObject.openConnection();
connection.setRequestProperty("Authorization", "Basic " + encoding);
connection.setRequestMethod("POST");
String postParameters = "X='xyz'";
connection.setDoOutput(true);
connection.connect();
DataOutputStream outputStreamToConnection = new DataOutputStream(
connection.getOutputStream());
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(outputStreamToConnection, "ISO-8859-1"));
writer.write(postParameters);
writer.close();
outputStreamToConnection.flush();
outputStreamToConnection.close();
int responseCode = connection.getResponseCode();
任何人都知道导致第一次拒绝Tomcat的原因是什么?我记录了我的标头请求,第一次和第二次请求的标题是相同的......
看起来客户端会缓存一些东西。它在SAP AS Java服务器上运行。希望任何人都遇到同样的问题。 :) 谢谢 本