我不确定如何根据这些信息编写正确的 UnityWebRequest.Post :
curl --location --request POST 'https://url.com/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'Authorization: Basic UE5weXFUUUZjU1NTSkQ4eDFzQ0Fh' \
--header 'Cookie: ASP.NET_SessionId=qqjltxh; LSW_WEB=gatewaytraffic01; back_apim-tst_https=gateway-swarm-manager-03' \
--data-urlencode 'grant_type=client_credentials'
此请求的目的是获取令牌。我试过这样写请求:
WWWForm form = new WWWForm();
form.AddField("Content-Type", "application/x-www-form-urlencoded");
form.AddField("Authorization", "Basic UE5wzQ0Fh");
form.AddField("Cookie" ,"ASP.NET_SessionId=qqjxh; LSW_WEB=gatewaytraffic01; back_apim-tst_https=gateway-swarm-manager-03");
form.AddField("grant_type" ,"client_credentials");
UnityWebRequest uwr = UnityWebRequest.Post("https://url.com/token", form);
yield return uwr.SendWebRequest();
我收到错误 401,我真的不确定“Cookie”和“grant_type”字段。当我发送没有这些字段的请求时,我收到错误 400。
有人可以解释我应该如何做这个请求吗?
谢谢。