PC SOFT

FOROS PROFESIONALES
WINDEVWEBDEV y WINDEV Mobile

Inicio → WINDEV 2024 → HTTPRequest / connecting to Wordpress / Anybody know how to decode JQuery into Windev?
HTTPRequest / connecting to Wordpress / Anybody know how to decode JQuery into Windev?
Iniciado por guest, 04,nov. 2017 18:54 - 2 respuestas
Publicado el 04,noviembre 2017 - 18:54
Hi,

I'm trying to connect to a wordpress site and get a Json web token back.

This is the code I am sending

sURL is string="https://ardemo.agency.atlasrepublic.co/wp-json/jwt-auth/v1/token"
sUser is string="xxxxxx"
sPwd is string="xxxxxx"

sHTTPRequest is httpRequest

sHTTPRequest..User=sUser
sHTTPRequest..Password=sPwd
sHTTPRequest..URL=sURL
sHTTPRequest..Method=httpPost
sHTTPRequest..ContentType="application/json"

cMyResponse is httpResponse = HTTPSend(sHTTPRequest)
IF ErrorOccurred THEN
Error(ErrorInfo(errFullDetails))
ELSE
Info(cMyResponse..Content)
END

When I execute this I get the following error back.

{"code":"jwt_auth_bad_auth_header","message":"Authorization header malformed.","data":{"status":403}}

1. I have not been able to figure out how to display what the content of message being sent is so I have no what to know what teh message actually looks like. Any tips on how to trap that?

2. The instructions for how to do this in JQuery are below. I don;t know JQuery so I'm not sure what, if anything I'm missing. Anyone know how to read this to see what, if anything I'm missing?

$.ajax({
url: 'https://ardemo.agency.atlasrepublic.co/wp-json/jwt-auth/v1/token',
method: 'POST',
crossDomain: true,
beforeSend: function ( xhr ) {
xhr.setRequestHeader( 'Authorization', 'Basic ' + Base64.encode( 'username:password' ) );
},
success: function( data, txtStatus, xhr ) {
console.log( xhr.status );
},
error: function( error ) {
console.log( error );
}
});

Thanks!

Steve
Publicado el 04,noviembre 2017 - 18:57
Hi Steve,

I don't know jquery either, but this:
Base64.encode( 'username:password' ) );
Seems to mean that you need to encode your username and password in base 64...

So that's the first thing I would try

Best regards
Publicado el 06,noviembre 2017 - 19:43
This is what ended up working..


sURL is string
sURL="https://ardemo.agency.atlasrepublic.co/wp-json/jwt-auth/v1/token"
sHTTPRequest is httpRequest
sHTTPRequest..Header["Accept"] = typeMimeJSON
sHTTPRequest..URL=sURL
sHTTPRequest..Method=httpPost
sHTTPRequest..Content="username="+sUser+"&password="+sPwd


cMyResponse is httpResponse = HTTPSend(sHTTPRequest)
IF ErrorOccurred THEN
Error(ErrorInfo(errFullDetails))
ELSE
Info(cMyResponse..Content)
END