Restsharp Exception无法识别URI前缀
本文关键字:URI 前缀 识别 Exception Restsharp | 更新日期: 2023-09-27 18:03:30
我从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;
}
您需要确保包含像http://
或https://
这样的URI前缀。只发送url some.company.com/api/person/add
而不发送http://some.company.com/api/person/add
会导致这个错误