Otro Nancy.Testing.Browser GET/PUT/POST/DELETE
Frecuentes
Visto 1,391 veces
1
Usando el Marco de Nancy... http://nancyfx.org/
Si quiero usar el objeto Navegador en el lado del cliente para consumir el servicio de Nancy, como vemos en este ejemplo: 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();
});
...
¿Tengo que usar Nancy.Testing aunque mi aplicación no esté probando? En otras palabras, ¿existe otro objeto del navegador que realice operaciones de obtención, colocación, publicación y eliminación como este objeto?
2 Respuestas
1
Encontré la clase System.Net.WebClient también hace GET/PUT/POST/DELETE, por ejemplo
//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);
Pero, finalmente, decidí usar el cliente WCF REST con webHttpBinding
. Algo como esto:
[ServiceContract]
public interface IMyService
{
[OperationContract]
[WebGet(UriTemplate = "{docId}")]
void GetData(string docId);
}
Clase de hormigón:
class MyClient: ClientBase<IMyService>, IMyService
{
public void GetData(string docId)
{
Channel.GetData(docId);
}
}
Respondido el 28 de junio de 12 a las 15:06
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas c# nancy or haz tu propia pregunta.