login about faq

Hi all,

[Using the Java Bundle version 9.5.0.59]

I want to retrieve data from a REST-resource that requires a valid user to be authenticated using Basic HTTP access authentication. If I use CkRest#SetAuthBasic, like in this code fragment (error handling etc. removed for clarity), a HTTP Status 401 is returned:

CkRest rest = new CkRest();
//
rest.SetAuthBasic("kermit", "kermit");
//
rest.Connect("localhost", 9090, false, true);
rest.AddHeader("Content-Type","application/json; charset=UTF-8");
String jsonResponseStr = rest.fullRequestNoBody("GET","/activiti-rest/service/runtime/tasks");
System.out.println(jsonResponseStr);

Returns: HTTP Status 401

If I explicitly calculate and insert an 'Authorization' header, the request gets authenticated and a result is returned:

CkRest rest = new CkRest();
//
CkByteData data = new CkByteData();
CkString authString = new CkString();
data.appendStr("kermit:kermit");
data.encode("base64", authString);
//
rest.Connect("localhost", 9090, false, true);
rest.AddHeader("Authorization", "Basic "+authString.getString());
rest.AddHeader("Content-Type","application/json; charset=UTF-8");
String jsonResponseStr = rest.fullRequestNoBody("GET","/activiti-rest/service/runtime/tasks");
System.out.println(jsonResponseStr);

Returns: valid data.

We would prefer to use the SetAuthBasic() method, but for some reason this does not work. Can anybody tell me how I should use this method or why this is going wrong?

Regards, Rui

asked Oct 16 at 10:54

RuiRosado's gravatar image

RuiRosado
31


Chilkat will not allow sending Basic Authentication over a non-secure connection. In other words, an SSL/TLS connection is required to send the Basic Authentication, otherwise the login/password is visible for all to see.

However, in this case, I see that it is a connection to localhost, and Chilkat should allow for that exception. I'll make this exception automatic in the next version released (9.5.0.62).

link

answered Oct 16 at 12:19

chilkat's gravatar image

chilkat ♦♦
11.8k316358420

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×28
×11

Asked: Oct 16 at 10:54

Seen: 90 times

Last updated: Oct 16 at 12:19

powered by OSQA