SD. Net (Http processing class; suitable for SDK, web page capturing, and simulated requests), sd. netsdk

Source: Internet
Author: User

SD. Net (Http processing class; suitable for SDK, web page capturing, and simulated requests), sd. netsdk

This class has the following features:
Supports Fluent APIs;
Automatically process Cookies (Supports automatic sharing of Cookies for all links, automatic sending of Cookies by domain name, and automatic intercept of 301/302 redirect Cookies );
Supports HTTPS;
Certificates are supported;
Support proxy;
Supports Session persistence;
Supports JSON/XML requests;
Support automatic JSONP content identification as JSON;
Supports Multifile upload and download;
Supports automatic GZIP;
Supports automatic parsing of webpage code;
Supports converting responses to files, text, images, memory streams, byte arrays, and deserialization into Entity classes;
Support Jquery Dom query (SD. Net. Html. dll needs to be introduced in the ToDom method );
Next version:
[To be developed] supports resumable upload of Files
[To be developed] supports asynchronous programming
Completed
Modification history:
[2016-01-14]:
Fixed the failure of automatic decoding;
[11-11-27]:
Adjust the IHttpRequest Interface Definition and add the UseGlobalCookies attribute to support sharing Cookies by all instances.
Adjust the IHttpRequest Interface Definition and add the AllowAutoRedirect attribute to control whether to automatically redirect to the latest page.
Adjust the IHttpRequest Interface Definition and add the SetCookie (CookieCollection cookies) method.
Adjust the IHttpRequest Interface Definition and add the SetHeader (WebHeaderCollection headers) method.
Adjust HttpClient and add the OnRequest and OnResponse methods.
Add CookieStore to manage global cookies
Remove ActionUrl and BaseUrl, defined as Url
[2015-10-10]:
Adjust the IHttpRequest Interface Definition and add the Clone method.
[]:
Adjust the IHttpRequest Interface Definition and add the Set, SetHeader, and SetCookie methods.
[]:
Adjust the IHttpRequest interface definition, add the SetBody, ClearXX, OnRequest, OnResponse, And Go methods, remove the SetObject method, and adjust some function definitions to support Xml
[]:
Added the IHttpResponse interface to extend the class to get data of the text, File, Stream, and Bytes types.
[2015-06-21]:
Basic class built

 Sample Code:
[Note]: The following http://www.demo.com/web site needs to be replaced with the actual web site.

[Example 1]:
Var http = HttpClient. Create ();
Var txt1 = http. Go ("http://www.demo.com/"). GetResponse (). ToText ();
Var json = http. Go ("http://www.demo.com/http/Porudct/1"). GetResponse (). ToType (typeof (Porudct ));
Var img1 = http. Go ("http://www.demo.com/img/logo.png"). GetResponse (). ToImage ();
/***/Http. Go ("http://www.demo.com/img/logo.png"). GetResponse (). ToFile ("C:/1.jpg ");

[Example 2]:
Var dom = HttpClient. Create ("https://www.baidu.com/s? Wd = a "). ToDom ();
Var title = dom. Find ("title: first"). Text (); // title: a _ Baidu search
Var list = dom. Find ("# content_left h3.t"). Select (p => p. InnerText). ToList (); // list: All search link titles
Var list = dom. Find ("# content_left h3.t"). Elements. Select (p => p. InnerText). ToList (); // list: All search link titles

[Example 3]:
Var login = HttpClient. Create ("http://www.demo.com/Login", "POST ")
. SetParameter (new
{
LoginAccount = "/* account */",
LoginPassword = "/* password */"
})
. SetParameter ("VerifyCode", "/* Verification Code */")
. SetHeader ("Client-ID", "0 ")
. GetResponse ()
. ToText ();
Var home = HttpClient. Create ("http://www.demo.com", "GET ")
. GetResponse ()
. ToText ();
//
Var title = JQuery. Create (home). Find ("head> title: first"). Text ();

[Example 4]:
Var form = HttpClient. Create ("http://www.demo.com/User/Save", "POST ")
. SetParameter (new
{
ID = 1,
Name = "Jom ",
Data = new {A = "small", B = "not set", C = 0}
})
. SetFile ("Photo", "C:/1.jpg ")
. GetResponse ()
. ToText ();

Related Article

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.