[HttpPost] Interface
public string Post ([Frombody] string bjbh)
{
var DWGC = new Object ();
string output = string. Empty;
String msg = string. Empty;
bool result = true;
String errorCode = "200";
Try
{
var dwgcbybjbhlist = db. BASE_GETDWGCXXBYBJBH (BJBH);
DWGC = new
{
page = PageIndex,
Total = Dwgcbybjbhlist. Count ()%pagesize==0? Dwgcbybjbhlist. Count ()/pagesize:dwgcbybjbhlist. Count ()/pagesize + 1, records = Dwgcbybjbhlist. Count (),
Dwgcxx =dwgcbybjbhlist//. (x = X.BJBH). Skip (pagesize* (pageIndex-1)). Take (pageSize). ToList (),}; }
catch (Exception ex)
{
result = false;
msg = ex. Message;
ErrorCode = "300";
}
Finally
{
var Dwgcjson = new
{
result = result,//execute normal return True, exception returns false
ErrorCode = ErrorCode,//Error number information
Message = MSG,//Description of performance
data = DWGC,//contract information
};
Output = Newtonsoft.Json.JsonConvert.SerializeObject (Dwgcjson);
}
return output;
}
Call
private String Webapitest ()
{
String poststring = "= 3333333";
byte[] PostData = System.Text.Encoding.UTF8.GetBytes (poststring); Coding, especially Chinese characters, in advance to see how to crawl the page encoding
var client = new WebClient ();
Client. Headers.add ("Content-type", "application/x-www-form-urlencoded");
Client. Headers.add ("Accept", "Application/json, Text/javascript, */*; q=0.01 "), or//to take the post must be added to the header, if you change to get the way to remove this sentence can be
String newurl = "HTTP://LOCALHOST/XMSGXKZSERVICE/V1/GETDWGCBYBJBH";
byte[] ResponseData = client. Uploaddata (Newurl, "POST", postdata); Get a stream of returned characters
String value1 = Encoding.UTF8.GetString (responsedata);
return value1;
}
Calling the Webapi interface