Postman vs URLConnection

Im making a call to a REST endpoint using a URLConnect subclass that I expect return a Bearer token nad it does perfectly on Postman but not for me via Webapp or desktop. I have tried 9 ways to sunday to reformat this body with and without quotes etc, no joy. If i inspect the Postman setup in their console it is the form-urlencoded type and I also noticed postman is TSL1.2 - could that be the issue? I just keep getting a 400 error saying the grant_type is unsupported but it works fine in postman. Anyone see this before?

me.ClearRequestHeaders
var requestContent as string = "{"+_
&u22 + "grant_type" + &u22 +  ":" + &u22 + "client_credentials" + &u22 + "," +_
&u22 + "client_id" + &u22 + ":" + &u22 + "aaaaaaax@3eb556347477377015870" + &u22 + "," +_
&u22 + "client_secret" + &u22 + ":" + &u22 +"67568jjrt87titirtirt0a42e16b0c0a"+ &u22 +"}"

me.SetRequestContent(requestContent, "application/x-www-form-urlencoded")
me.RequestHeader("Content-Type") = "application/json"
var payload as string ="https://myendpoint.com/token"
me.Send("POST", payload)

The requestContent string appears to be in JSON format, but it should be application/x-www-form-urlencoded format.

Try this:

var requestContent as string = "grant_type=client_credentials&client_id=" + EncodeURLComponent("aaaaaaax@3eb556347477377015870") + "&client_secret=67568jjrt87titirtirt0a42e16b0c0a"
me.SetRequestContent(requestContent, "application/x-www-form-urlencoded")
me.Send("POST", payload)
1 Like

Thank you so much Andrew - that was it. Now it seems so obvious. Aaargh! Im not sure why i thought it but I was thinking the requestContent as that type was handling it but I should have know when looking at it in the debugger it wasnt… Appreciate it!!