The current Windows Phone platform supports the following ways to implement network requests: HttpWebRequest, WebClient, WebBrowser, Socket I personally give them a class: Most practical, most troublesome: HttpWebRequest Most Concise: WebClient Most wretched: WebBrowser Most infrequently used: Socket Possible use of some WP source case: http://code.662p.com/list/14_1.html 1.HttpWebRequest: can achieve a variety of WP support request type (currently support Post/get), support cookies, support complex post protocol, the definition is very free, but the process is more cumbersome, the rules are the most, a little careless will go wrong, but the implementation of efficiency also with the best one
2.WebClient: Compared to HttpWebRequest, it does not support cookies first, but the amount of code is small, a simple request may only require a few lines of code, and HttpWebRequest need more code, and less control than HttpWebRequest, Sometimes there are some inexplicable errors, but compared to HttpWebRequest is indeed a lot simpler, when appropriate, the use of WebClient can effectively improve development efficiency, reduce the complexity of the code.
3.WebBrowser: Why is that so wretched? This stems from a development experience, because WP does not support the GB2312 character set, there are many pages are GB2312, and at that time we do not have a server, only on the client to the HTML processing, crawling the required content, and then the other groups all stuck in the GB2312 transcoding work, At this time I found WebBrowser, it can be used to send get requests, but also support JavaScript, and no matter what encoding, ie can give you normal transcoding, you just need to call the relevant method after the request to the content to extract the HTML string, compared to the previous two, are convenient and concise ... This is simply too wretched! |