2015-08-13 20 views
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 
     } 
    } 
+1

使用[requestb.in](http://requestb.in/)看看你发送到DocuSign。您的代理基本身份验证可能正在发送给DocuSign,这不是预期的。向你的代理人投诉。他们破坏你的工作应用程序的事实应该是他们需要解决的问题。 –

回答

0

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

您使用代理的基本身份验证可能正在发送给DocuSign,这是平台所不期望的。

抱怨你的代理人。事实上,他们打破了你的工作应用程序应该是他们的问题,以解决...