HTTPSocket works fine in Mac but not in Windows

Using a Xojo.Net.HttpSocket I have the following wired problem:
Works fine in Mac but not in Windows

I first send a GET request to obtain a Authorization Token and then I send a POST request placing the Authorization token in the Header

Var strMyAccessToken as string = "Bearer " + strAccessToken
Var textAccessToken as text = strAccessToken.totext
MySocket.RequestHeader(“Authorization”) = textAccessToken

Var data As Xojo.Core.MemoryBlock = Xojo.Core.TextEncoding.UTF8.ConvertTextToData(MyJson)
MySocket.Send(“POST”, MyUrl)

The JSON I receive as response is as follows:

{“fault”:{“faultstring”:“Invalid access token”,“detail”:{“errorcode”:“oauth.v2.InvalidAccessToken”}}}

And the provider of the webservice is saying to me that I am passing a wrong Authorization Token.

When sending JSON data, you often have to set a header along with the POST verb, e.g.

Content-Type: application/json

See for some examples of doing this using cURL.

Can you tell if Xojo is setting that header automatically?

@Mike_D Thanks for answering.

What I am asking is if there is something to consider that makes my code works different when running a Windows or a Mac compilation, so the webservice invoked receive an invalid access token in one case. The Access token is passed in the header of the message, an the header is created with the same code for both a windows app and a mac app.

encodings maybe different
you mix string and text together.

Try using URLConnection that should work for both platforms and elimiate most of the encoding issues.

1 Like

I had found the solution…!!!

Just for the records:
In windows, prior to this line of code:
MySocket.RequestHeader(“Authorization”) = textAccessToken
you have to
I don´t know why this line of code is not necessary in Mac.