我正在尝试对 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;