0

我已经成功创建了我的应用程序,现在想将其连接到本地主机以检查我的应用程序的工作情况。有人建议我使用 restsharp 连接到服务器,使用 php 和 json 从服务器接收数据。

我已经查看了两者的代码,但并不完全理解该过程是如何工作的。我查看了所有论坛,但发现了没有解释它是如何工作的片段。我什至尝试过 restsharp.org 和谷歌搜索结果。请向我解释这是如何工作的。

4

1 回答 1

0

RestSharp 是一个帮助您调用 REST Web 服务的库。
您在客户端上使用 RestSharp 来调用 Rest 样式 Web 服务(发送和接收数据) 以下是您的服务使用示例:
var client = new RestClient(baseUrl);

var request = new RestRequest("/*rest_resource*/", Method.POST);
// see Rest services

// set the request format - HTTP Content-Type text/xml
request.RequestFormat = DataFormat.Xml;

// add data to the request
request.AddBody("<books><book>RestSharp Book</book></books>");

/* send the request and if your service returns text put the as expected return type; otherwise you will get raw byte array*/
IRestResponse response = client.Execute(request);

//HTTP status code 200-success
Assert.IsTrue(response.StatusCode == HttpStatusCode.OK);
Assert.IsTrue(!string.IsNullOrEmpty(response.Data)); // the response is not empty

于 2013-07-24T09:56:46.680 回答