C# 如何在c中使用FRED Rest服务#
我尝试使用提供的REST服务。不幸的是,我不知道如何使用它。 到目前为止我所做的:C# 如何在c中使用FRED Rest服务#,c#,rest,hammock,C#,Rest,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"); //c
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;
您正在发出POST请求,但从未指定
从中,提取要发出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
部分是代码中缺少的第一个部分 谢谢!我尝试了你添加的代码。我不需要证件,或者?我在两者中都添加了一个空字符串。有了这些,我从弗雷德那里得到了网页,但没有图片??