2018-05-15
RestSharp 106.2.2 - Simple REST and HTTP API Client
https://www.nuget.org/packages/RestSharp/
RestSharp - Simple REST and HTTP Client for .NET
http://restsharp.org/
using RestSharp; using System; namespace WebApplication3 { public partial class Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { //var client = new RestClient((string)ConfigurationManager.AppSettings["RESTfulUrl"] + "rest/getContacts"); var client = new RestClient("http://abc.def.com.tw/rest/getContacts"); var request = new RestRequest(Method.POST); //request.RequestFormat = DataFormat.Json; //request.AddHeader("Accept", "text/plain"); //request.AddHeader("Content-Type", "application/json"); request.AddHeader("Content-Type", "application/x-www-form-urlencoded"); request.AddParameter("username", "user1"); request.AddParameter("password", "pass1"); var response = client.Execute(request); var content = response.Content; // raw content as string } } } |
(完)
沒有留言:
張貼留言