使用南希框架...... http://nancyfx.org/
如果我想在客户端使用Browser对象来使用Nancy服务,就像我们在此示例中看到的那样:https://github.com/NancyFx/Nancy/wiki/Testing-your-application
...
var bootstrapper = new DefaultNancyBootstrapper();
var browser = new Browser(bootstrapper);
// When
var result = browser.Get("/", with => {
with.HttpRequest();
});
...
我是否必须使用Nancy.Testing即使我的应用程序没有测试???换句话说,是否存在其他浏览器对象,其执行Get,Put,Post和Delete操作,就像这个对象一样?
答案 0 :(得分:3)
答案 1 :(得分:1)
我发现System.Net.WebClient类也执行GET / PUT / POST / DELETE e.g。
//Creating client instance and set the credentials
var client = new WebClient();
client.Credentials = new NetworkCredential(...);
// using GET Request:
var data = client.DownloadData("http://myurl/.../" + docId);
// Using PUT
var data = Encoding.UTF8.GetBytes("My text goes here!");
client.UploadData("http://myurl/...", "PUT", data);
// Using POST
var data = new NameValueCollection();
data.Add("Field1", "value1");
data.Add("Field2", "value2");
client.UploadValues("http://myurl/...", "POST", data);
但是,最后我决定将WCF REST客户端与webHttpBinding
一起使用。像这样:
[ServiceContract]
public interface IMyService
{
[OperationContract]
[WebGet(UriTemplate = "{docId}")]
void GetData(string docId);
}
具体类:
class MyClient: ClientBase<IMyService>, IMyService
{
public void GetData(string docId)
{
Channel.GetData(docId);
}
}