RejectedSoftware Forums

Sign up

How to send authorised requests?

For example, I have this code:

import vibe.core.log;
import vibe.http.client;
import vibe.stream.operations;

void test()
{
	requestHTTP(`http://username:password@127.0.0.1:1234",
		(scope req) {
			req.method = HTTPMethod.POST;
			req.writeJsonBody(["name": "My Name"]);
		},
		(scope res) {
			logInfo("Response: %s", res.bodyReader.readAllUTF8());
		}
	);
}

It doesn't work, I have the error 401 Unauthorized.. Note that the same code works fine via std.net.curl.

Am I miss something, or Vibe.d's vibe.http.client.requestHTTP haven't got support of authorised requests?

Re: How to send authorised requests?

On Sat, 18 Jan 2014 21:02:54 GMT, ilya-stromberg wrote:

For example, I have this code:

import vibe.core.log;
import vibe.http.client;
import vibe.stream.operations;

void test()
{
	requestHTTP(`http://username:password@127.0.0.1:1234",
		(scope req) {
			req.method = HTTPMethod.POST;
			req.writeJsonBody(["name": "My Name"]);
		},
		(scope res) {
			logInfo("Response: %s", res.bodyReader.readAllUTF8());
		}
	);
}

It doesn't work, I have the error 401 Unauthorized.. Note that the same code works fine via std.net.curl.

Am I miss something, or Vibe.d's vibe.http.client.requestHTTP haven't got support of authorised requests?

Is the server on the other hand also a vibe.d based server? I could imagine that URL based passwords are not fully supported in some areas, will look into it.

To use header based basic auth instead, you can call req.addBasicAuth(username, password) (needs import vibe.http.auth.basic_auth;).

Re: How to send authorised requests?

On Sun, 19 Jan 2014 13:13:10 GMT, Sönke Ludwig wrote:

Is the server on the other hand also a vibe.d based server? I could imagine that URL based passwords are not fully supported in some areas, will look into it.

No, it's third-party server. I haven't got problems with it, so it's Vibe.d's client error.

To use header based basic auth instead, you can call req.addBasicAuth(username, password) (needs import vibe.http.auth.basic_auth;).

Everything is fine when I add req.addBasicAuth(username, password) header manually, thank you.

Also, when I created vibe.inet.url.URL struct manually it also fails. Probably, you don't use URL.username and URL.password fields.

Re: How to send authorised requests?

On Sun, 19 Jan 2014 16:04:28 GMT, ilya-stromberg wrote:

On Sun, 19 Jan 2014 13:13:10 GMT, Sönke Ludwig wrote:

Is the server on the other hand also a vibe.d based server? I could imagine that URL based passwords are not fully supported in some areas, will look into it.

No, it's third-party server. I haven't got problems with it, so it's Vibe.d's client error.

To use header based basic auth instead, you can call req.addBasicAuth(username, password) (needs import vibe.http.auth.basic_auth;).

Everything is fine when I add req.addBasicAuth(username, password) header manually, thank you.

Also, when I created vibe.inet.url.URL struct manually it also fails. Probably, you don't use URL.username and URL.password fields.

username/password have been completely ignored in URL.toString. It's fixed now in a4af111.

Re: How to send authorised requests?

On Tue, 21 Jan 2014 13:19:28 GMT, Sönke Ludwig wrote:

username/password have been completely ignored in URL.toString. It's fixed now in a4af111.

No, I still have 401 Unauthorized. error.
Still works fine with req.addBasicAuth(username, password) header.

Re: How to send authorised requests?

On Wed, 22 Jan 2014 15:00:14 GMT, ilya-stromberg wrote:

On Tue, 21 Jan 2014 13:19:28 GMT, Sönke Ludwig wrote:

username/password have been completely ignored in URL.toString. It's fixed now in a4af111.

No, I still have 401 Unauthorized. error.
Still works fine with req.addBasicAuth(username, password) header.

Upon taking a slightly closer look, it's still missing support in the HTTP client to automatically perform addBasicAuth when a username/password is found in the URL. I've filed an issue for now.

Re: How to send authorised requests?

On Mon, 27 Jan 2014 13:23:13 GMT, Sönke Ludwig wrote:

On Wed, 22 Jan 2014 15:00:14 GMT, ilya-stromberg wrote:

On Tue, 21 Jan 2014 13:19:28 GMT, Sönke Ludwig wrote:

username/password have been completely ignored in URL.toString. It's fixed now in a4af111.

No, I still have 401 Unauthorized. error.
Still works fine with req.addBasicAuth(username, password) header.

Upon taking a slightly closer look, it's still missing support in the HTTP client to automatically perform addBasicAuth when a username/password is found in the URL. I've filed an issue for now.

Damian Ziemba aka nazriel was so kind and solved this with pull #501. Looks like everything should finally work now.