UCWA 2.0 尝试添加前向联系但收到 ParameterValidationFailure

UCWA 2.0 Trying to add forward contact but getting ParameterValidationFailure

我正在使用 UCWA 2.0 在我们的 Intranet Web 应用程序中进行一些 Skype4Business 集成。

我可以成功连接并执行一些操作,例如:更改可用性状态或询问用户的呼叫转移设置。

我喜欢做的是为用户设置转发联系人。 相关文档:click here

我的 POST 调用代码:

 using (var client = new HttpClient())
 {
     var param = new { target = "sip:user@domain.be" };
     var paramJson = JsonConvert.SerializeObject(param, Formatting.Indented);

     client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
     client.DefaultRequestHeaders.Referrer = new Uri(result4._links.xframe.href);
     client.DefaultRequestHeaders.Add("Authorization", $"{result3.token_type} {result3.access_token}");

     var url = $"https://ucwebext.domain.be/{applicationUrl}/me/callForwardingSettings/immediateForwardSettings/immediateForwardToContact";

     var responseNew = await client.PostAsync(url, new StringContent(paramJson, Encoding.UTF8, "application/json"));
     var responseString = await responseNew.Content.ReadAsStringAsync();
}

使用 RestSharp 的相同代码:

var client = new RestClient($"https://ucwebext.domain.be/{applicationUrl}");

var restR = new RestRequest("/me/callForwardingSettings/immediateForwardSettings/immediateForwardToContact", Method.POST);

var param = new { target = "sip:user@domain.be" };
var jsonToSend = JsonConvert.SerializeObject(param, Formatting.Indented);

restR.AddParameter("application/json; charset=utf-8", jsonToSend, ParameterType.RequestBody);
restR.AddParameter("referer", result4._links.xframe.href);

restR.AddHeader("Authorization", $"{result3.token_type} {result3.access_token}");

restR.RequestFormat = DataFormat.Json;

var response = client.ExecuteAsPost(restR, "POST");

请求 header 来自电话:

POST https://ucwebext.domain.be/ucwa/oauth/v1/applications/101024253230/me/callForwardingSettings/immediateForwardSettings/immediateForwardToContact   HTTP/1.1
Accept: application/json
Referer: https://ucwebext.domain.be/Autodiscover/XFrame/XFrame.html
Authorization: Bearer cwt=AAEBHAEFAAAAAAAF...0Q_OXzsR4g4F-PpYaMGK10Pg
Content-Type: application/json; charset=utf-8
Host: ucwebext.domain.be
Content-Length: 48
Expect: 100-continue

{"target":"sip:user@domain.be"}

我收到以下错误:

{"code":"BadRequest","subcode":"ParameterValidationFailure","message":"Please check what you entered and try again.","parameters":[{ "name":"target","reason":"MissingOrInvalid"}]}

我什么都试过了,不明白为什么参数没有提交或无效。

非常感谢任何帮助!

解决方案

我没有使用 JSON,而是将参数添加为有效的查询字符串!

 var client = new RestClient($"https://ucwebext.domain.be/{applicationUrl}");
 var restR = new RestRequest($"/me/callForwardingSettings/immediateForwardSettings/immediateForwardToContact{Url.Encode("?target=sip:user@domain.be")}", Method.POST);

 restR.AddParameter("referer", result4._links.xframe.href);
 restR.AddHeader("Authorization", $"{result3.token_type} {result3.access_token}");

 var response = client.ExecuteAsPost(restR, "POST");