I am getting a error that I do not understand. It looks like credentials are accepted. Here is my code.
public static void main(String[] args) throws Exception
{
// GET section
DefaultHttpClient httpclient = new DefaultHttpClient();
CredentialsProvider credentials = new BasicCredentialsProvider();
credentials.setCredentials(
new AuthScope(“<wiki-mine.com>”,<port>, “<realm>"),
new UsernamePasswordCredentials(“<user>", “<password>"));
HttpGet req = new HttpGet(“https://<wiki-mine.com>:<port>:8443/conflunce/rest/api/content/?title=Test+Page&spaceKey=~<user>");
req.addHeader("accept", "application/json");
req.setHeader("Content-Type", "application/json");
final HttpResponse response = httpclient.execute(req);
final int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != 200) {
System.out.println("Request has failed, status code: " + statusCode);
System.exit(-1);
} else {
final InputStream content = response.getEntity().getContent();
System.out.println(IOUtils.toString(content));
IOUtils.closeQuietly(content);
}
This is the output:
{"errorMessage":"You are not logged in. <a href=\"/login.action\">Log in<\/a> here and try again.”}
Should this return the page?
thanks
Hi
2 things I have noticed...
you have a typo in the url, unless your context path is really conflunce (and not confluence)
httpclient.setCredentialsProvider(credentials);
Hope it helps...
Hi I fixed the url, and added httpclient.setCredentialsProvider(credentials);. It still gives the same error. I think its is authentication problem because when I use a incorrect password it yields the same error. curl works fine and returns the page contain. Any ideas? Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What if you just use the SeraphAuthentication params Confluence expects https://developer.atlassian.com/display/CONFDEV/HTTP+authentication+with+Seraph DefaultHttpClient httpclient = new DefaultHttpClient(); HttpGet req = new HttpGet("https://<wiki-mine.com>:<port>:8443/confluence/rest/api/content/?title=Test+Page&spaceKey=~<user>&os_username=<user>&os_password=<password>";); final HttpResponse response = httpclient.execute(req);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks that works, but it is return html, not json. Even tho set the req header to request json with: req.addHeader("accept", "application/json"); req.setHeader("Content-Type", "application/json"); Is there a way to get json content as curl returns?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Just checked, it does nicely return application/json on our test server (no apache infront, just confluence tomcat) response.getEntity().getContentType() and it seems it does not matter if I set or not the above mentioned headers
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hum, its coming back as Content-Type: text/html;charset=UTF-8 for me. Could it be a difference in server setup?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
which version of Confluence do you use (tried with 5.6.6 just now once again) and do you have some web server in-front of Confluence (like apache or something)?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
We are running Confluence version 5.6.4. IT is checking to see if Apache is involved, but I think not. I checked to make sure the headers where indeed being set, but it does not matter if they are set or not.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
IT confirmed that there is not wed server in-front of Confluence.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
what version of HTTP commons you are using? Just very curious to understand the difference...tried with 4.3.2 trying to understand if there is an issue with redirect or something also, what do you see in Development Tools when you request the same URL via for example Chrome browser (what is the content type, response body?)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
http commons 4.3.1. curl does not get a redirect it just sends back the correct json. firefox gets rediected to https://wiki.<domain>r.com:8443/dashboard.action, and displays the page. httpclient also goes to the dashboard, and returns the html for that page. also I can post a new page from curl, but when I do so from httpclient I get a 302 (found) or 200 if setRedirectStrategy(new LaxRedirectStrategy()); is called.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
And the new page never shows up in confluence. I was using the same authentication in the curl as the post
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
frankly, I am completely lost, as if I do http://localhost:1990/confluence/rest/api/content/?title=More+information&spaceKey=ds&os_username=admin&os_password=admin on vanilla development version of Confluence it does nicely returns the application/json and the content. HTTP code is 200, no redirects Same goes when I run a java code provided above
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
thanks for all your help. I have it working now. It was a context path problem.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.