URLConnection: Can't see my request headers etc

Im using the chilkat plugin so it does all that heavy lifting.

// INSTANTIATE OBJECT
Var jwt As New Chilkat.Jwt // Build the JOSE header
Var jose As New Chilkat.JsonObject // SET ALGORITHM
Var success As Boolean
success = jose.AppendString("typ","JWT")
success = jose.AppendString("alg","HS256") // BUILD CLAIMS
Var claims As New Chilkat.JsonObject
success = claims.AppendString("secret", secretStr)
success = claims.AppendString("iss", issStr)
Var strJwt As String = jwt.CreateJwt(jose.Emit(),claims.Emit(), secretStr) // DEBUG TO STDOUT
System.DebugLog(jose.Emit())
System.DebugLog("Claims JSON String: " + claims.Emit())
System.DebugLog("JSON String: " + strJwt) Return strJwt

JWT doesnā€™t ask for authenticationā€¦ it just expects it in the header.

As mentioned in my thread, try putting a trailing slash on your request and see if that makes a difference.

In case youā€™re wondering how I noticed it, I actually ended up tailing the apache log file after making a configuration edit that included more infoā€¦ it wasnā€™t until I saw the requests from Xojo and Postman on top of each other that I realized that one had a trailing slash and one didnā€™t.

1 Like

Thanks I just saw that. Trying that also. -> I donā€™t have any trailing slashes in my POST URL. Thanks @Kristin_Green for the idea as this must be something else.

Put one in anyways.

Oh i misread your other thread ā€“ adding now.

Same 400 ā€“ :frowning:

I found that JWT server I used spat back the same ā€œAuthentication credentials were not provided.ā€ error even though the issue had nothing to do with authentication. So, donā€™t trust the error message.

I also found that some clients automatically inserted a trailing slash in the background so it wasnā€™t immediately obvious.

Is the server under your control or is it someone elseā€™s? If itā€™s yours, Iā€™d be interested to know what youā€™re using.

Its under our Devā€™s control (My), but I did find my issue - and I hate I wasted some of your time, but fortunately it was a dumb white space char I missed in my copy/paste w/ my secret.

Somewhere between my broken code and fixed code I inserted it :frowning:

Thank you very much @DerkJand @Kristin_Green ā€“ I appreciate the help.

2 Likes

Mark the solution, it can always help othersā€¦:wink:

1 Like

Haha ā€“ Solution Marked as (me the dumb a$$ screwing up copy and pasting) :slight_smile:

Your not the first one, and wonā€™t be the lastā€¦

1 Like

FYI - Here is the feedback case to have Xojo expose the header / content to us in the URLConnection object similar to how HTTPSecureSocket allows us to view the header / content prior to post.

<https://xojo.com/issue/62171>

1 Like

Unfortunately that may not be possible. URLConnection uses system libraries to make the requests. HTTPSecureSocket would create the HTTP request itself, so getting an exact view of the output was possible because it was doing the work anyway. If the system classes donā€™t expose what would be needed, thereā€™s just no way to satisfy the request. I believe this is the case, as looking over URLSession (which I think URLConnection uses on Mac) I donā€™t see a way to get what you need. Though I could be wrong, I just took a quick look.

Would sure be useful though.

1 Like

Yes - When I explain to my dev colleagues that use JetBrains Intelli-J they are almost amazed we canā€™t see this info.

I bet we could if URLConnection had used curlā€¦

2 Likes