English 中文(简体)
Java HTTP PUT with Digest accreditation in Java
原标题:Java HTTP PUT with Digest authentication in Java

我正试图用PUT<>/strong>将档案上载到 Java,服务器确实是文摘认证。 我想保持其精干,因此,我尝试使用。 HttpURLConnection.

public void putData(String path, byte [] data) throws IOException, MalformedURLException {

Authenticator.setDefault(new Authenticator() {
      protected PasswordAuthentication getPasswordAuthentication() {
          return new PasswordAuthentication(user,password.toCharArray());
      }});

  debug("Default authenticator set");
  //Safeguard against double slashes
  if (path.startsWith("/")) {
   path = path.replaceFirst("/","");
  }

  debug(hostname + path);
  URL url = new URL(hostname + path);
  HttpURLConnection conn = (HttpURLConnection) url.openConnection();
  debug("HttpURLConnection acquired");
  conn.setDoOutput(true);
        conn.setDoInput(true);

  conn.setRequestMethod("PUT");
  conn.setRequestProperty("Content-Length",String.valueOf(data.length));
  conn.setRequestProperty("Content-type","application/binary");
  conn.setFixedLengthStreamingMode(data.length);
  conn.connect();

  debug("Properties set");
  OutputStream out = conn.getOutputStream();
  debug("Outputstrem acquired");
  out.write(data,0,data.length);
  out.flush();
  out.close();
  debug("Data written, stream closed."); 
 }

出于某种原因,这种情况毫无希望: 我看到401人回来,然后回去。 如果我不同意授权,同样的法典就能够发挥作用。 利用消化认证“公正工程”下载具有类似代码的文档 任何想法? 我确实不是开始使用阿帕奇语的周边这么多图书馆(......2010年......),你期望在任何标准图书馆内使用“消化”网站。

问题回答

您至少应在方法结束时尝试<代码>conn.getInputStream(),以强制评价服务器的反应。 否则,服务器的潜在错误信息将无法适当发现。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...