【问题标题】:Consuming Oracle ORDS RESTful api with C#使用 C# 使用 Oracle ORDS RESTful api
【发布时间】:2019-01-16 09:56:00
【问题描述】:

我收到以下关于使用 C# 使用 ORDS Oracle RESTful 数据服务的响应。

{ 状态码:405, ReasonPhrase: '方法不允许', 版本:1.1, 内容:System.Net.Http.StreamContent, 标题: { 内容长度:11402 内容类型:文本/html } }

public void test()
{
    string item_code;

    using(var client = new HttpClient())
    {
        Item items = new Item
        {
            segment1 = "049002932",
            description = "Fine Liner Dollar Pointer Softliner Metal Jacket F 0.3 Black 10's Box",
            short_description = " Pointer F Black 10's Box", service_item = "No", primary_uom_code = "10", inventory_item_status_code = "Inactive"
        };

        client.BaseAddress = new Uri("http://10.132.1.40:8090/");

        var response = client.PutAsJsonAsync("ords/ebsvis1/raz_inv/raz_item/Update/", items).Result;

        if (response.IsSuccessStatusCode)
            Console.Write("Success");
        else
            Console.Write("Error");
    }
}

这是我的 RESTful 服务定义:

【问题讨论】:

    标签: c# oracle rest webservice-client oracle-ords


    【解决方案1】:

    对于基于 ORDS 的 RESTful 服务,是否为 raz_inv 模块和 .../Update/ 模板定义了 PUT 处理程序?

    根据您的屏幕截图,这是 PUT Hander URI:

    /raz_inv/raz_item/update/{item_code}
    

    但是,你正在做一个 PUT

    /raz_inv/raz_item/Update/
    

    您需要在 URI 的末尾包含项目代码,所以这样做

    var response client.PutAsJsonAsync("ords/ebsvis1/raz_inv/raz_item/Update/049002932",  items).Result;
    

    只是猜测 049002932 位...

    【讨论】:

    • 我在 ORDS 中创建了一个 PUT 方法,这就是我使用 PutAsJsonAsync 的原因
    • 我附上了截图。您可以在上面的链接中看到。
    • {StatusCode: 405, ReasonPhrase: 'Method Not Allowed', Version: 1.1, Content: System.Net.Http.StreamContent, Headers: { Content-Length: 11402 Content-Type: text/html }}
    • 你能在你的代码之外使用 API,你能用 Insomnia 或 Postman 之类的东西来做 PUT 吗?另外,什么是“项目” - 您是否将其附加到 URI?抱歉,我不会说 C#
    • 商品代码为 Json 格式,更新数据库中存在的商品描述。但是,我会按照您的建议在我的代码之外进行尝试。将让您了解最新进展。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-01-05
    • 2020-07-29
    • 2012-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多