如何在c#中使用FRED Rest服务

本文关键字:FRED Rest 服务 | 更新日期: 2023-09-27 18:09:41

我尝试使用FRED with Hammock来使用提供的REST服务。不幸的是,我不知道如何使用它。到目前为止我做了什么:

string url = "http://wit.istc.cnr.it/stlab-tools/fred/api";
Hammock.RestClient client = new Hammock.RestClient();
client.AddHeader("Accept", "image/png -F text=Miles Davis was an american jazz musician");
//client.AddHeader("Accept", "text=Miles Davis was an american jazz musician");
client.Authority = url;
Hammock.RestRequest req = new Hammock.RestRequest();
req.Path = url;
Hammock.RestResponse response = client.Request(req);
string _result = client.Request(req).Content;

如何在c#中使用FRED Rest服务

您正在发出POST请求,但您从未指定。


从juniper.net中提取POST请求:

public void makeQRest() {
    try {
        string auth = "http://wit.istc.cnr.it/stlab-tools/fred/api";
        string body = "text=Miles Davis was an american jazz musician";
        IWebCredentials credentials = new Hammock.Authentication.Basic.BasicAuthCredentials {
            Username = Config.uName,
            Password = Config.pWord
        };
        RestClient client = new RestClient {
            Authority = auth,
        };
        client.AddHeader("content-type", "Accept: image/png");
        RestRequest request = new RestRequest {
            Credentials = credentials,
            Method = WebMethod.Post
        };
        request.AddPostContent(Encoding.UTF8.GetBytes(body));
        RestResponse response = client.Request(request);
        Console.WriteLine("the create Queue status is " + response.StatusCode);
        Console.WriteLine(response.Content);
        Console.ReadLine();
    } catch (Exception e) {
        Console.WriteLine(e.Message);
        Console.ReadLine();
    }
}

Method = WebMethod.Post部分是代码中第一个缺失的东西。