How to invoke interfaces provided by other web sites

Source: Internet
Author: User

These days, the results of Baidu, summed up an example: a website to provide send SMS interface business interface: Service_url variable parameter: username,pwd,mobiles,content return: <returninfo>resultcode </ReturnInfo>
1. Build the sent XML or other form of the request string postdata = string. Format ("Actioncode=sms01&username=mine&pwd=123&mobiles={0}&content={1}", StrMobiles, strMessage+ "Customer Service Center" ");and convert the request into byte formatbyte[] data = Encoding.Default.GetBytes (PostData), 2, with HttpWebRequest to send the establishment request HttpWebRequest Myrequest = (HttpWebRequest ) WebRequest.Create (Service_url);3, write to the request related properties of the request, that is, the requested header format (Request method, version type, the requested character encoding, response time, etc.)Myrequest.            Method = "POST"; Myrequest.            ContentType = "application/x-www-form-urlencoded"; Myrequest. ContentLength = data. Length;4, writes request information to the request using (Stream Datasteam = myrequest. GetRequestStream ()) {Datasteam. Write (data, 0, data.                Length); Datasteam.            Close (); }5. Get Response Request httpwebresponse myresponse = myrequest. GetResponse ()  as httpwebresponse;6, reading data from the response    HttpWebResponse myResponse =  Myrequest. GetResponse ()  as HttpWebResponse;             using  (Streamreader reader = new streamreader (                                                      myresponse.getresponsestream ()                                                     ,&nbSp System.Text.Encoding.GetEncoding ("Utf-8"))              {                 Response = reader. ReadToEnd ();                 Xmldoc.loadxml (response);                 reader. Close ();            The general return from the Web site is a string of XML format 7, the string is converted to XML format, and take out the relevant data xmldocument xmldoc = new system.xml.xmldocument (); string result = Xmldoc.selectsinglenode ("Returninfo"). InnerText;

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.