我有以下代碼以asana創建任務。響應給出了錯誤
String data = "{" + " \"data\": {"
+ "\"workspace\":4661999437107,"
+ "\"name\": \"crmit solutions\","
+ "\"notes\": \"NOTES_ABOUT_TASK_GO_HERE\","
+ "\"assignee\": \"[email protected]\"" + "}"
// + " \"options\": {" + " \"fields\": \"name\"}"
+ "}";
HttpClient client = new HttpClient();
client.getParams().setAuthenticationPreemptive(true);
client.getParams().setParameter("http.useragent", "Test Client");
client.getState().setCredentials(
new AuthScope("app.asana.com", 443, "realm"),
new UsernamePasswordCredentials(
"1k3qqT7O.RVRyxHdHRLiYSH710c6NpVl", ""));
BufferedReader br = null;
PostMethod method = new PostMethod(
"https://app.asana.com/api/1.0/tasks");
method.setDoAuthentication(true);
try {
method.setRequestBody(data);
int returnCode = client.executeMethod(method);
System.out.println("Return code: " + returnCode);
br = new BufferedReader(new InputStreamReader(
method.getResponseBodyAsStream()));
String readLine;
while (((readLine = br.readLine()) != null)) {
System.out.println(readLine);
}
} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
method.releaseConnection();
if (br != null)
try {
br.close();
} catch (Exception fe) {
System.err.println(fe);
}
}
,但它給我一個錯誤說返回代碼:400 { 「錯誤」:[{ 「消息」: 「工作區:類型不正確」}]}
請幫助!
您的建議很好,但在這種情況下,它不會真正解決他的問題。我們應該改進錯誤信息,使其更清楚地表明它所指的對象是錯誤的類型,而不是JSON值。 :) – 2013-03-26 16:43:36