c# - Restsharp 异常 URI 前缀无法识别

标签 c# restsharp

我收到来自 RestSharp 的异常 The URI prefix is not recognized并且不明白为什么。

参数

requestBody只是一个 POCO

domainsome.company.com

_config.AddPersonEndpointapi/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/

相关文章:

c# - MVC 2.0 模型绑定(bind)是否适用于 Ajax 请求?

c# - 为什么在 RestClient.Execute 工作时将 RestClient.ExecuteAsync 与 await 一起使用会静默失败?

c# - RestSharp 中的对象到 JSON 问题

azure - Xamarin + RestSharp + .Net Core Web API - 值不能为空。参数名称 : src

c# - 使用 RestSharp 在 multipart/form-data POST 中包含文件时出现问题

c# - C#中如何获取请求

c# - GetHashCode问题

c# - 从部分类访问类字段

c# - 如何在没有 NuGet 的情况下安装和设置 RESTSharp?

c# - 将位图编码为 Jpeg