HTTP POST with user & password combined

Discussions related to HTTPAPI (An HTTP Client Package for RPG programming.) http://www.scottklement.com/httpapi/
Post Reply
jtaylor
Posts: 15
Joined: Tue Dec 21, 2021 10:51 pm

HTTP POST with user & password combined

Post by jtaylor »

I need to call a web service and the spec says that the user and password must be base64 encoded and sent all together. Their docs say:
This header will consist of three items, the static value “Basic” followed by a base64 encoded string that contains your user name and password separated by a colon
The docs show

Code: Select all

Authorization: Basic VXNlcm5hbWU6UGFzc3dvcmQ=
as an example.

Is there a way to accomplish this with http_url_post() and http_setauth()?


TIA
Scott Klement
Site Admin
Posts: 872
Joined: Sun Jul 04, 2021 5:12 am

Re: HTTP POST with user & password combined

Post by Scott Klement »

Code: Select all

http_setAuth(HTTP_AUTH_BASIC: UserID: Password);
Then run http_url_post (or preferably one of the newer routines) and it will use the userid/password you've set.
jtaylor
Posts: 15
Joined: Tue Dec 21, 2021 10:51 pm

Re: HTTP POST with user & password combined

Post by jtaylor »

I can do that. I know user/password in POSTMAN doesn't work, and I guessed it was the weird user:password encoded as one string. I assumed that would be an issue in HTTPAPI as well.

Thanks
Scott Klement
Site Admin
Posts: 872
Joined: Sun Jul 04, 2021 5:12 am

Re: HTTP POST with user & password combined

Post by Scott Klement »

jtaylor wrote: Wed Dec 22, 2021 2:44 pmI know user/password in POSTMAN doesn't work, and I guessed it was the weird user:password encoded as one string.
Can you explain this better?

The standard for basic authentication is to concatenate the userid and password (with a colon between them) and then base64 encode it. That sounds exactly like what you are describing, right?

This is part of the core HTTP standard, required for all HTTP clients to implement. I know that PostMan does, in fact, work fine with this -- I've used it before. All web browsers support it. SoapUI supports it. Everything does -- it's the most common authentication type out there.

Or, are you saying that instead of user:password you have a string that doesn't contain two separate parts, but has a single string without the colon? That would indeed be weird, and would not be following the HTTP standard. (You can do different authentication types following your own scheme, but you can't refer to them as "basic")
jtaylor
Posts: 15
Joined: Tue Dec 21, 2021 10:51 pm

Re: HTTP POST with user & password combined

Post by jtaylor »

I think their documentation is just misleading. It says the username must be upper case, and that you must manually encode the credentials yourself. Both are wrong. I corrected the case in Postman and my RPG code, and both succeed.

Thank you for your help.
Post Reply