Projects tigase _server server-core Issues #1459
rest api 302 Temporary Redirect (#1459)
Unknown opened 3 years ago

I have a problem with… After I pass "api_key" as a parameter, I report an error of "302 temporary redirection". After I write "open_access" in the configuration file, I do not pass "api_key", but I also report the same error of temporary redirection. There is no configuration about redirection in my configuration file. How should I solve it? Thank you very much Details (please complete the following information):

  • Tigase version: [e.g. 8.1.2]
  • JVM flavour and version [OpenJDK11]
  • Operating system/distribution/version [Linux centos7]
Unknown commented 3 years ago

Tigase XMPP Server does not support api_key but only api-key parameter

Unknown commented 3 years ago

Tigase XMPP服务器不支持api_key,但只有api-key参数

How do I use it?

This is my code, error reported 302 temporary redirection

        HttpClient client = new DefaultHttpClient();
        HttpPost  post = new HttpPost("http://im.aeeago.com:8080/rest/stream");
        String sendString ="<message xmlns=\"jabber:client\" type=\"chat\"  to=\"zcy@im.aeeago.com\"><body>{\"type\":1,\"msgid\":\"dsf\",\"content\":\"test\"} </body></message>";
        System.out.println(sendString);
        StringEntity entity = new StringEntity(sendString,"utf-8");
        entity.setContentType("application/xml");
        entity.setContentEncoding("utf-8");
        post.setEntity(entity);
        HttpResponse response= null;
        try {
            response = client.execute(post);
        } catch (IOException e) {
            e.printStackTrace();
        }```
Unknown commented 3 years ago

Tigase XMPP服务器不支持api_key,但只有api-key参数

What should I do with "each request needs to be authorized by sending a valid administrator JID and password as user and password of BASIC HTTP authorization method." in the document? The error I am reporting is 403 Forbidden, image

Unknown commented 3 years ago

In order to make HTTP request you need to:

  1. pass api-key (configured in HTTP api key repository via admin web ui)
  2. authenticate the request using HTTP Basic access authentication. You can find how to do that using search engine: duckduckgo: java httpclient basic auth, eg.:
val httpClient: HttpClient = HttpClient.newBuilder()
            .connectTimeout(Duration.ofSeconds(10))
            .authenticator(object : Authenticator() {   
                override fun getPasswordAuthentication(): PasswordAuthentication {
                    return PasswordAuthentication("admin", "password".toCharArray())
                }
            })
            .version(HttpClient.Version.HTTP_1_1)
            .build()

    val request = HttpRequest.newBuilder()
            .GET()
            .uri(URI.create("http://im.aeeago.com:8080/rest/stream"))
            .build()

    val httpResponse = httpClient.send(request, BodyHandlers.ofString())
    println("httpResponse statusCode = ${httpResponse.statusCode()}")
    println(httpResponse.body())
issue 1 of 1
Type
Question
Issue Votes (0)
Watchers (0)
Reference
tigase/_server/server-core#1459
Please wait...
Page is in error, reload to recover