Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When sending the request sending a json I get the error " Can't check the token Validity". Previously I have obtained the token which is stored in a variable. The statusCode: OK {200}.

What I observe with the error that is displayed is that the json cannot be sent because the token is not being validated. However, if I do the tests in postman with the token and the json , the result is correct. I am using the RestSharp/106.15.0.0 library which is the same one with which I obtain the token.

The code in vb.net 2015 that I have developed is the following:

VB
Dim client = New RestClient("" & Var_URLWS & "")
Dim request2 = New RestRequest(Method.POST)
request2.AddHeader("Content-Type", "application/json")
request2.AddHeader("Authorization", Mybearer" & MyToken)
request2.AddJsonBody(MyJson, "application/json")
Dim response2 As RestResponse = client.Execute(request2)


What I have tried:

I have tried adding other lines of code like request2.AddBody(MyJson) request2.AddHeader("Cache-Control", "no-cache") I have carried out the tests in postman which are satisfactory
Posted
Updated 12-Feb-23 19:35pm
Comments
Dave Kreskowiak 13-Feb-23 7:54am    
Why do noobs nearly always do this?
... New RestClient("" & Var_URLWS & "")

There is ZERO reason to put empty quotes on the beginning and ending of a string variable. All you're doing is making your code more prone to errors and more difficult to debug.

That line should read:
... New RestClient(Var_URLWS)
Member 12760369 13-Feb-23 8:42am    
Yes, I do hazing, but always with an open mind to keep moving forward. That's why I participate in these groups. I made the change you told me and it works. Thanks for your help.

1 solution

That code doesn't compile, much less run:
VB
request2.AddHeader("Authorization", Mybearer" & MyToken)
                                    ^       ^
                                    ?       ?
You have an unmatched double quote in there.

If it doesn't compile, then that's not the version of code you are executing - so the error you are getting is from a previous version of the code.
 
Share this answer
 
Comments
Member 12760369 13-Feb-23 8:47am    
Correct, I mistyped the code when asking the question, sorry, the one that is originally compiled is "request2.AddHeader("Authorization", "Mybearer " & MyToken) and it returns the mentioned error message.
Thank you so much

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900