0

我已成功创建我的应用程序,现在想要将其连接到本地主机以检查我的应用程序的工作。我建议使用restsharp连接到服务器使用php和json从服务器接收数据。RestSharp用于发送和接收数据

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

+0

换句话说,你需要的是如何连接的例子到Windows Phone 7应用程序上的RESTful服务,最好使用RestSharp客户端库包装器?顺便说一下,HTTPClient可移植类库可以无缝地执行此操作,除非您希望使用restsharp的特定功能。 – FunksMaName

回答

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

+0

我也想在从服务器接收数据时使用Json。我需要Json来区分服务器接收到的数据并将其置于文本框所需的位置。我如何去做? – nik

+0

上面的示例代码显示了如何使用RestSharp调用Rest Web服务。换句话说,你是如何从服务器接收数据的。 RestSharp还提供了以Json格式发送和接收数据的功能。查看这个[thread](http://stackoverflow.com/questions/16156738/restsharp-deserialization-with-json-array)作为json与restsharp的例子。 – sundog