UCWA 2.0 尝试添加转发联系人但获取 ParameterValidationFailure

Posted

技术标签:

【中文标题】UCWA 2.0 尝试添加转发联系人但获取 ParameterValidationFailure【英文标题】:UCWA 2.0 Trying to add forward contact but getting ParameterValidationFailure 【发布时间】:2018-01-08 14:24:29 【问题描述】:

我正在使用 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");

来自调用的请求标头:

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":"请检查您输入的内容,然后重试。","parameters":["name":"target", "原因":"MissingOrInvalid"]

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

非常感谢任何帮助!

【问题讨论】:

【参考方案1】:

解决方案

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

 var client = new RestClient($"https://ucwebext.domain.be/applicationUrl");
 var restR = new RestRequest($"/me/callForwardingSettings/immediateForwardSettings/immediateForwardToContactUrl.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");

【讨论】:

以上是关于UCWA 2.0 尝试添加转发联系人但获取 ParameterValidationFailure的主要内容,如果未能解决你的问题,请参考以下文章

Lync 2013 Web API (UCWA) 位置

在 Android 2.0 上添加联系人号码

用于获取 Lync 状态的 UCWA 集成

创建应用程序时 UCWA OAuth 令牌无效

UCWA 活动频道适合订阅大量用户吗?

Skype for Business UCWA oauth 问题,尝试创建 ucwa 应用程序时出现错误 401