0
我從Docusign Rest API walk through中使用了以下代碼。由於我在代理後面添加了代理信息。通過代理服務器的DocuSign REST API
public HttpURLConnection initializeRequest(String url, String method,
String body, String httpAuthHeader) {
try {
Proxy proxy = new Proxy(Proxy.Type.HTTP,
new InetSocketAddress("proxyServer address", proxyPort));
conn = (HttpURLConnection) new URL(url).openConnection(proxy);
conn.setRequestMethod(method);
conn.setRequestProperty("X-DocuSign-Authentication",
httpAuthHeader);
conn.setRequestProperty("Accept", "application/json");
if (method.equalsIgnoreCase("POST")) {
conn.setRequestProperty("Content-Type",
"multipart/form-data; boundary=BOUNDARY");
conn.setDoOutput(true);
} else {
conn.setRequestProperty("Content-Type", "application/json");
}
return conn;
} catch (Exception e) {
throw new RuntimeException(e); // simple exception handling
// please review it
}
}
這是運行良好但最近代理需要身份驗證,我在我的REST調用得到一個未經授權的401錯誤。
我確實更改了代碼以使其中包含驗證器,但我仍然遇到同樣的問題,有什麼建議可以嘗試,除此之外?
public HttpURLConnection initializeRequest(String url, String method, String body, String httpAuthHeader) {
try {
Proxy proxy = new Proxy(Proxy.Type.HTTP,
new InetSocketAddress("proxyServerAdress", intPort));
Authenticator authenticator = new Authenticator() {
public PasswordAuthentication getPasswordAuthentication() {
return (new PasswordAuthentication("username",
"password".toCharArray()));
}
};
Authenticator.setDefault(authenticator);
conn = (HttpURLConnection) new URL(url).openConnection(proxy);
conn.setRequestMethod(method);
conn.setRequestProperty("X-DocuSign-Authentication",
httpAuthHeader);
conn.setRequestProperty("Accept", "application/json");
if (method.equalsIgnoreCase("POST")) {
conn.setRequestProperty("Content-Type",
"multipart/form-data; boundary=BOUNDARY");
conn.setDoOutput(true);
} else {
conn.setRequestProperty("Content-Type", "application/json");
}
return conn;
} catch (Exception e) {
throw new RuntimeException(e); // simple exception handling
// please review it
}
}
使用[requestb.in](http://requestb.in/)看看你發送到DocuSign。您的代理基本身份驗證可能正在發送給DocuSign,這不是預期的。向你的代理人投訴。他們破壞你的工作應用程序的事實應該是他們需要解決的問題。 –