0

我正在尝试对 URL https://jazz.net/进行发布请求。我收到以下错误。

调用 javascript 函数“addTwoIntegers”失败:未授权”

FWLSE0101E: 原因:org.apache.http.client.HttpResponseException:未经授权

这是我的java代码:

    HttpGet query = new HttpGet(projectAreaURI);
    HttpPost q= new HttpPost(projectAreaURI);
    HttpClient httpClient=new DefaultHttpClient();
    HttpUtils.setupLazySSLSupport(httpClient);
    q.addHeader("Accept","application/xml");
    
    q.addHeader("Accept-Encoding","gzip");
    q.addHeader("User-Agent","yes");
    q.addHeader("Content-Type","application/x-www-form-urlencoded");
    String postMessage="offlineData={'projectAreaItemId':'_iTuLUmxfEeKR3t32SVbLKQ','executables':[{'terItemId':'_TNoyQW6qEeKR3t32SVbLKQ','scriptItemId':'_DF89AW6qEeKR3t32SVbLKQ'}]}";
    q.setEntity(new ByteArrayEntity(
            postMessage.toString().getBytes("UTF8")));
    
    query.addHeader("Accept", "application/xml");
    
    
    // Access to the Service Descriptor document
    HttpResponse response = HttpUtils.sendPostForSecureDocument(projectAreaURI, q, "ashwinimaddala", "ash_1646",httpClient);
    if (response.getStatusLine().getStatusCode() != 200) {
        response.getEntity().consumeContent();
        throw new     HttpResponseException(response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase());
    }
    return response.getStatusLine().getStatusCode()+"";
    

sendPostForSecureDocument():

    if (DEBUG)
        System.out.println(">> PUT(1) " + put.getURI());
    HttpResponse documentResponse = httpClient.execute(put);
    if (DEBUG) {
        System.out.println(">> Response Headers:");
        HttpUtils.printResponseHeaders(documentResponse);
    }
    System.out.println(documentResponse.getStatusLine().getStatusCode());

    if (documentResponse.getStatusLine().getStatusCode() == 200) {
        System.out.println(put.getURI());

        Header header = documentResponse.getFirstHeader(AUTHREQUIRED);
        if ((header != null) && ("authrequired".equals(header.getValue()))) {
            documentResponse.getEntity().consumeContent();
            HttpPost formPost = new HttpPost(serverURI
                    + "/j_security_check");
            List<NameValuePair> nvps = new ArrayList<NameValuePair>();
            nvps.add(new BasicNameValuePair("j_username", login));
            nvps.add(new BasicNameValuePair("j_password", password));
            formPost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
if (DEBUG)
                System.out.println(">> POST " + formPost.getURI());
            HttpResponse formResponse = httpClient.execute(formPost);
            if (DEBUG)
                HttpUtils.printResponseHeaders(formResponse);

            header = formResponse.getFirstHeader(AUTHREQUIRED);
            if ((header != null)
                    && ("authfailed".equals(header.getValue()))) {
                throw new InvalidCredentialsException(
                        "Authentication failed");
            } else {
                formResponse.getEntity().consumeContent();
                if (DEBUG)
                    System.out.println(">> PUT(2) " + put.getURI());
                try {
                    HttpPut put2 = (HttpPut) put.clone();
                    return httpClient.execute(put2);
                } catch (CloneNotSupportedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    return documentResponse;
4

1 回答 1

0

重新访问这个问题,在我看来这可能是这里报告的相同问题:org.apache.http.conn.HttpHostConnectException: Connection to https://jazz.net denied

基本上,jazz.net 需要使用端口 443。所以在您的 Java 代码中,就像在 Worklight 适配器中一样,确保您使用端口 443...

于 2013-04-19T08:16:54.480 回答