0
我正在嘗試向URL https://jazz.net/發送一個請求。我收到以下錯誤。 javascript函數 'addTwoIntegers' 的基於Java的適配器中的HttpResponseException
調用失敗:未經授權」
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;
請檢查服務器日誌中是否有異常併發布堆棧跟蹤。 – user1983983 2013-04-09 12:36:36
我無法找到服務器日誌在這裏..它是一個Java適配器我寫在worklight項目.. – 2013-04-09 16:16:29
功能「addTwoIntegers」在哪裏?你是否將整個項目放在示例應用程序.....? – 2013-04-11 05:12:54