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