通过代理服务器提供DocuSign REST API

时间:2015-08-13 16:46:15

标签: java rest proxy docusignapi

我从Docusign Rest API walk through使用了以下代码。由于我在代理后面,我添加了代理信息。

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
        }
    }

运行正常但最近代理需要身份验证,我在其余的通话中收到未经授权的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
        }
    }

1 个答案:

答案 0 :(得分:0)

使用requestb.in查看您通过代理服务器发送给DocuSign的内容。

您使用代理的基本身份验证可能正在发送到DocuSign,而平台不期望这样做。

向您的代理人投诉。他们打破你的工作应用程序的事实应该是他们修复的问题......