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

时间:2013-04-18 06:45:31

标签: c# rest hammock

我尝试使用FRED 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;

1 个答案:

答案 0 :(得分:0)

您正在发出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部分是您代码中第一个丢失的内容。