1

我尝试将FREDHammock一起使用以使用提供的 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;
4

1 回答 1

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部分是您的代码中第一个缺少的东西。

于 2013-04-18T06:59:09.253 回答