【发布时间】:2021-07-12 08:53:42
【问题描述】:
我不确定如何根据这些信息编写正确的 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。
有人能解释一下我应该怎么做这个请求吗?
谢谢。
【问题讨论】:
-
--header表示,此信息属于标题,而不是正文。
标签: c# asp.net unity3d unitywebrequest