Hello,

I was trying to write a program which would upload new pages on my wiki. I
was following these instructions
http://platform.xwiki.org/xwiki/bin/view/Features/XWikiRESTfulAPI , but
unfortunately most of the examples use old version of Apache's HTTP library,
so they are not very useful for me. 

So I decided to try writing a program by following Apache's examples, but
when I was testing connectivity I realised that I can't even get access to
admin-only pages.

Here's my code:

import java.io.IOException;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

public class RestTest {

        public static void main(String[] args) throws IOException {
                CredentialsProvider credsProvider = new
BasicCredentialsProvider();
        credsProvider.setCredentials(
                new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT,
AuthScope.ANY_REALM, AuthScope.ANY_SCHEME),
                new UsernamePasswordCredentials("Tobi", "mypass"));
        CloseableHttpClient httpclient = HttpClients.custom()
                .setDefaultCredentialsProvider(credsProvider)
                .build();
        try {
            HttpGet httpget = new
HttpGet("http://xwiki.aircr.ru/xwiki/bin/edit/Main/WebHome";);

            System.out.println("Executing request " +
httpget.getRequestLine());
            CloseableHttpResponse response = httpclient.execute(httpget);
            try {

System.out.println("----------------------------------------");
                System.out.println(response.getStatusLine());
                EntityUtils.consume(response.getEntity());
            } finally {
                response.close();
            }
        } finally {
            httpclient.close();
        }
    }

}

It gives me:
Executing request GET http://xwiki.aircr.ru/xwiki/bin/edit/Main/WebHome
HTTP/1.1
----------------------------------------
HTTP/1.1 401 Unauthorized


I would really appreciate any help! Also, it would be great if you show me
more examples of using PUT method for xWiki RESTful!



--
View this message in context: 
http://xwiki.475771.n2.nabble.com/xWiki-RESTful-HTTP-Connection-tp7599026.html
Sent from the XWiki- Users mailing list archive at Nabble.com.
_______________________________________________
users mailing list
users@xwiki.org
http://lists.xwiki.org/mailman/listinfo/users

Reply via email to