简体   繁体   English

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

[英]How to use FRED Rest service with c#

I try to use FRED with Hammock to use the provided REST service. 我尝试将FREDHammock结合使用以使用提供的REST服务。 unfortunately I have no idea how to use it. 不幸的是,我不知道如何使用它。 what I did so far: 我到目前为止所做的:

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;

You're making a POST request but you never specify that. 您正在发出POST请求,但从未指定该请求。


From juniper.net , an extract to make POST Request: 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();
    }
}

The Method = WebMethod.Post part is the first missing thing in your code. Method = WebMethod.Post部分是代码中首先缺少的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM