我收到来自 RestSharp 的异常 The URI prefix is not recognized
并且不明白为什么。
参数
requestBody
只是一个 POCO
domain
是 some.company.com
和
_config.AddPersonEndpoint
是 api/person/add
public PersonResponse AddPerson(PersonRequest requestBody, string domain)
{
var client = new RestClient(domain);
var request = new RestRequest(_config.AddPersonEndpoint, Method.POST);
request.RequestFormat = DataFormat.Json;
request.AddBody(requestBody);
var response = client.Execute<PersonResponse>(request);
if (response.ErrorException != null)
throw response.ErrorException;
if (response.ErrorMessage != null)
throw new PortalConnectivityException(response.ErrorMessage);
if (!string.IsNullOrEmpty(response.Data.ErrorMessage))
throw new PortalException(response.Data.ErrorMessage);
return response.Data;
}
最佳答案
您需要确保包含 URI 前缀,例如 http://
或 https://
。仅发送网址 some.company.com/api/person/add
而不是 http://some.company.com/api/person/add
将导致此错误
关于c# - Restsharp 异常 URI 前缀无法识别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23687245/