1

I try to use FRED with Hammock to use the provided REST service. 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;
thecoshman
  • 8,394
  • 8
  • 55
  • 77
tro
  • 914
  • 2
  • 10
  • 23

1 Answers1

0

You're making a POST request but you never specify that.


From juniper.net, an extract to make POST Request:

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.

thecoshman
  • 8,394
  • 8
  • 55
  • 77
Francesco De Lisi
  • 1,493
  • 8
  • 20
  • thanks! I tried your added code. I don't need credentials, or? I added a empty string to both. with that I got back the webpage from FRED but no image?? – tro Apr 18 '13 at 09:04