Java DefaultHttpClient HTTP PUT和Cookie

时间:2015-01-17 15:49:29

标签: java put youtrack

我向YouTrack api发送请求以创建问题。

    String url = yBaseUrl + "/rest/issue?Task&"+ URLEncoder.encode(subject)+"&"+URLEncoder.encode(desc);

    HttpClient client = new DefaultHttpClient();
    HttpPut request = new HttpPut(url);

    // add request header
    ((DefaultHttpClient) client).setCookieStore(cookie);
    HttpResponse response = null;
    //client.execute(post);
    try {
        response = client.execute(request);
        System.out.println(response.getStatusLine().getStatusCode());
    } catch (IOException e) {
        e.printStackTrace();
    }

结果 - 403代码。

为什么setCookieStore不能正常工作?

1 个答案:

答案 0 :(得分:0)

问题是错误的api url。需要使用/休息/问题?项目 =任务& 摘要 =" + URLEncoder.encode(主题)...问题已关闭