具有UTF-8字符的Docusign Rest [英] Docusign Rest with UTF-8 Characters

查看:28
本文介绍了具有UTF-8字符的Docusign Rest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Docusign Rest API上传文档,我在电子邮件正文中有西班牙语字符,当收件人收到电子邮件时,它们不能正确显示.下面列出的是Java代码,我在其中将编码设置为UTF-8,并且在请求主体到达docusign服务器以及服务器所看到的内容之前,我已经粘贴了请求正文

I am trying to upload the Document using the Docusign Rest API, I have spanish characters in the body of the email and they are not displayed properly when Recipient gets the email. Listed below is the java code where I set the encoding to be UTF-8 and also I have pasted the Request Body before it hits the docusign server and also what the server is seeing

Java代码

public HttpURLConnection initializeRequest(String url, String method,
            String body, String httpAuthHeader) {
        try {

            Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(
                    "web.prod.proxy.company.com", 4200));
            conn = (HttpURLConnection) new URL(url).openConnection(proxy);
            conn.setRequestMethod(method);
            conn.setRequestProperty("X-DocuSign-Authentication", httpAuthHeader);
            conn.setRequestProperty("Accept", "application/json");
            conn.setRequestProperty("Accept-Charset", "UTF-8");
            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
        }
    }

在本地Box请求正文

  {
      "emailSubject" : "IRT16,17,18,19,20 MCI as of 11/10/2015",
      "emailBlurb" : "Buenos días/Tardes, \r\n\r\nAdjunto la documentación de la(s) transacción(es) con fecha de ejecución [Trade Date].  Rogamos que, en prueba de conformidad con los términos de la operación contenidos en esta Confirmación, nos devuelvan la copia adjunta debidamente firmada dentro de los siguientes dos días hábiles a partir de la fecha de ejecución. \r\n\r\nComo resultado de dicha(s) liquidación(es), [Cargill/Counterparty Name] deberá hacer un pago de US $XXX,XXX.XX el día [Payment date],  Adjunto la factura correspondiente. Por favor confirmar como quieren que se maneje este saldo.\r\n\r\nCualquier inquietud al respecto por favor comunicarse conmigo.\r\n\r\nUn cordial saludo,\r\n\r\n\r\nAttached is your intercompany statement as of 10-30-2015 with Cargill Risk Management.\r\n\r\nPlease confirm by filling out below template with your amounts and accounts and then replying to all. \r\n\r\n                              Please enter your amount:   Please enter your G/L account:\r\n\r\nPosition Market Value:                              \r\n\r\nPayable/Receivable:                                 \r\n\r\nYTD P&L:                                            \r\n\r\n2015-11-09",
      "recipients" : {
        "signers" : [ {
          "routingOrder" : "1",
          "name" : "John Doe",
          "email" : "John.Doe@gmail.com",
          "recipientId" : "1",
          "tabs" : {
            "signHereTabs" : [ {
              "anchorString" : "By:",
              "anchorXOffset" : "0",
              "anchorYOffset" : "0",
              "anchorIgnoreIfNotPresent" : "true",
              "anchorUnits" : "inches"
            } ]
          }
        } ],
        "carbonCopies" : [ ]
      },
      "documents" : [ {
        "name" : "CustomerOneSigner.pdf",
        "documentId" : "1",
        "bytes" : "Omitted for Better readablity"
      } ],
      "status" : "sent"
    }

要求机构提供什么Docusign接收器

Request Body what Docusign Recieves

{
  "emailSubject" : "IRT16,17,18,19,20 MCI as of 11/10/2015",
  "emailBlurb" : "Buenos d�as/Tardes, \r\n\r\nAdjunto la documentaci�n de la(s) transacci�n(es) con fecha de ejecuci�n [Trade Date].  Rogamos que, en prueba de conformidad con los t�rminos de la operaci�n contenidos en esta Confirmaci�n, nos devuelvan la copia adjunta debidamente firmada dentro de los siguientes dos d�as h�biles a partir de la fecha de ejecuci�n. \r\n\r\nComo resultado de dicha(s) liquidaci�n(es), [Cargill/Counterparty Name] deber� hacer un pago de US $XXX,XXX.XX el d�a [Payment date],  Adjunto la factura correspondiente. Por favor confirmar como quieren que se maneje este saldo.\r\n\r\nCualquier inquietud al respecto por favor comunicarse conmigo.\r\n\r\nUn cordial saludo,\r\n\r\n\r\nAttached is your intercompany statement as of 10-30-2015 with Cargill Risk Management.\r\n\r\nPlease confirm by filling out below template with your amounts and accounts and then replying to all. \r\n\r\n                              Please enter your amount:   Please enter your G/L account:\r\n\r\nPosition Market Value:                              \r\n\r\nPayable/Receivable:                                 \r\n\r\nYTD P&L:                                            \r\n\r\n2015-11-09",
  "recipients" : {
    "signers" : [ {
      "routingOrder" : "1",
      "name" : "John Doe",
      "email" : "John.Doe@gmail.com",
      "recipientId" : "1",
      "tabs" : {
        "signHereTabs" : [ {
          "anchorString" : "By:",
          "anchorXOffset" : "0",
          "anchorYOffset" : "0",
          "anchorIgnoreIfNotPresent" : "true",
          "anchorUnits" : "inches"
        } ]
      }
    } ],
    "carbonCopies" : [ ]
  },
  "documents" : [ {
    "name" : "CustomerOneSigner.pdf",
    "documentId" : "1",
    "bytes" : "Omitted"
  } ],
  "status" : "sent"
}

推荐答案

找到了一个解决方案,在调用POST方法之前,将请求正文转换为UTF-8,这样现在的代码便是

Found a Solution, before calling the POST method convert the request body to UTF-8 so the code now is

 String body = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(
                envelope);
    body =  docuSignUtils.convertToUTF8(body);            
    conn = initializeRequest(url, "POST", body,getAuthenticationHeader());

ConverttoUTF *功能是这样的

ConverttoUTF* function is something like this

 public  String convertToUTF8(String s) {
            String out = null;
            try {
                out = new String(s.getBytes("UTF-8"), "ISO-8859-1");
            } catch (java.io.UnsupportedEncodingException e) {
                return null;
            }
            return out;
        }

之前,我只是将EmailBlurb转换为UTF-8,但无法正常工作,我们需要将整个Envelope Object转换为UTF-8

earlier I was just converting the EmailBlurb into UTF-8 , which did not work we need to convert the whole Envelope Object into UTF-8

这篇关于具有UTF-8字符的Docusign Rest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆