Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
3
Erster Beitrag:
vor 1 Monat
Letzter Beitrag:
vor 1 Monat
Beteiligte Autoren:
steve erts, Fabrice Harari

HTTPRequest / connecting to Wordpress / Anybody know how to decode JQuery into Windev? (SOLVED)

Startbeitrag von steve erts am 04.11.2017 17: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

Antworten:

Re: HTTPRequest / connecting to Wordpress / Anybody know how to decode JQuery into Windev?

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

von Fabrice Harari - am 04.11.2017 17:57
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

von steve erts - am 06.11.2017 18:43
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.