Calling the Webapi interface

Source: Internet
Author: User

[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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.