UCWA 2.0 尝试添加转发联系人,但获取参数验证失败



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

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

我喜欢做的不起作用的是为用户提供一个转发联系人。相关文档:单击此处

我的开机自检调用代码:

 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","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");

相关内容

  • 没有找到相关文章

最新更新