java - Zoho Rest Invoice API 返回 400 错误,Java HttpClient
问题描述
我想在我的 Spring 应用程序中集成 Zoho Invoice API。我已经AuthToken
成功整合了一部分。现在我正在使用创建联系人 API。但 API 返回错误 400。
我正在使用以下代码:
public String processZohoRequest(String apiUrl,Map<String, String> params,String method, String auth) throws UnsupportedEncodingException, IOException {
URL url = new URL(apiUrl);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod(method);
if(!AppUtility.isEmpty(auth)) {
con.setRequestProperty("Authorization", auth);
con.setRequestProperty("Content-Type", "multipart/form-data");
con.setRequestProperty("X-com-zoho-invoice-organizationid", testZohoOrgId);
}
if(!AppUtility.isEmpty(params)) {
con.setDoOutput(true);
DataOutputStream out = new DataOutputStream(con.getOutputStream());
out.writeBytes(ParameterStringBuilder.getParamsString(params));
out.flush();
out.close();
}
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer content = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
content.append(inputLine);
}
in.close();
con.disconnect();
return content.toString();
}
我使用 sam 方法来获取正在工作的访问令牌,但是当使用它来创建联系人时它返回错误。谁能告诉我如何解决这个问题?
`API-URL`: https://invoice.zoho.com/api/v3/contacts
json String
:"{\"contact_name\":\"Jay Panjwanai\",\"company_name\":\"Ozone\",\"billing_address\":{\"注意\":\"Jay \",\"地址\":\"${address}\",\"city\":\"INDORE\",\"country\":\"India\",\"phone\":9xxxxxxxxx},\"shipping_address\" :{\"注意\":\"Jay\",\"地址\":\"${地址}\",\"城市\":\"INDORE\",\"国家\":\"印度\",\"电话\":9xxxxxxxxx}}"
提前致谢!
解决方案
好吧,在与他们的支持团队讨论后,我得到了答案。只需删除以下行:
con.setRequestProperty("Content-Type", "multipart/form-data");
这造成了一个问题。
问候
推荐阅读
- python - 基于另一列的唯一值对列的值求和
- c# - Autofac 和 RegisterGeneric - 限制允许的泛型
- javascript - 当单击“浏览”按钮并选择一个文件时,Django 的 FileField 到底在做什么?我可以用 Javascript 复制这种行为吗?
- python - 为什么 python pathlib Path('').exists() 返回 True?
- sql-server - SQL Server Reporting Services CSV 报告导出选项缺失
- python - sqlalchemy:如何返回加入 3 个表的对象列表?
- ssl - Asio 流式传输 - SSL/TLS 加密速度慢
- php - 将变体描述移至 Woocommerce 产品变量描述
- angular - Angular 中不再有来自 rxjs 6.X 的异步或回调
- android - Android-Studio 模拟器音频错误