我花了一周的时间试图弄清楚如何更新一些卡片信息,我希望一次更新大量字段,例如名称、desc、idList、已关闭等,但环顾四周后似乎它们必须是单独完成,但是当我尝试时,我不断收到 400 响应,并显示消息 "invalid value for value" 。
例如,当我尝试 PUT https://api.trello.com/1/cards/[cardid]/desc?key=[mykey]&token=[mytoken]value=just+yet+another+test+of+trello+侧面+扩展
我究竟做错了什么?
用于发送 Put 的 Java 代码是
private static InputStream doRequest(final String url, final String requestMethod, final Map<String, String> map)
{
try
{
final HttpsURLConnection conn = (HttpsURLConnection) new URL(url)
.openConnection();
conn.setRequestProperty("Accept-Encoding", "gzip, deflate");
conn.setDoOutput(requestMethod.equals(METHOD_POST) || requestMethod.equals(METHOD_PUT));
conn.setRequestMethod(requestMethod);
String plus = "";
if (map != null && !map.isEmpty())
{
final StringBuilder sb = new StringBuilder();
for (String key : map.keySet())
{
sb.append(sb.length() > 0 ? "&" : "")
.append(key)
.append("=")
.append(URLEncoder.encode(map.get(key), "UTF-8"));
}
conn.getOutputStream().write(sb.toString().getBytes());
conn.getOutputStream().close();
plus = sb.toString();
}
final int rc = conn.getResponseCode();
logger.info("response " + rc + " from " + requestMethod + " " + url + plus);
if (rc > 399)
{
return null;
}
else
{
return getWrappedInputStream(
conn.getInputStream(), GZIP_ENCODING.equalsIgnoreCase(conn.getContentEncoding())
);
}
}
catch (IOException e)
{
throw new TrelloException(e.getMessage());
}
}