An extension class of CookieContainer, cookiecontainer
The Cookie returned by the server is frequently used in recent projects. Because HttpClient is used in the project and CookieContainer is used to automatically host the Cookie, it is not convenient to obtain the Cookie. So I wrote an extension class.
First, retrieve all cookies through traversal, store the d
Recently I am working on a small software program that implements login and automatic sending of information through HttpWebRequest. Although it has not yet been implemented, today I have seen a good way to get CookieContainer from a foreign website, share it out. I have seen the least code and it is very good.
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->1 using System;
2 using System. Runtime. In
Cookies using System;
Using System.Net;
Using System.IO;
Using System.Text; [STAThread]
static void Main (string[] args)
{
//
TODO: Add code here to start the application
//
String url= "http://localhost/csdn2/1.asp";
If request ("AA") = "Zhuye" then session ("OK") = "OK"
If session ("OK") = "OK" then
Response.Write ("Login")
Else
Response.Write ("No login")
End If
%>
String Indata= "Aa=zhuye";
String Outdata= "";
Cookiecontainer mycookiecontainer=new
Pathlist has m_list Field
Sortedlist m_listKey: String pathValue: cookiecollection colcookies
So fromCookiecontainerObject, we can get the cookie object by this path:DomainString> path string> cookies. All cookies are grouped by path andDomain.This is the code that helping me to studyCookiecontainerObject, I get from http://channel9.msdn.com/forums/TechOff/260235-Bug-In-Cookiecontainer-Where-do-I-Report/thanks to johnwinner:
Public list getall
After a long time, I finally figured out the relationship between the two. I can't live up to my time in the morning ~~~
For more information about the nature of HttpWebRequest. CookieContainer and HttpWebResponse. Cookies, MSDN and many other blogs, I will not talk about them anymore. If you do not know about them, go and have a look.
Now let's talk about the differences between them. All the shoes that have used these two attributes have found that
Recently I am working on a small software program that implements login and automatic sending of information through httpwebrequest. Although it has not yet been implemented, today I have seen a good way to get cookiecontainer from a foreign website, share it with me. Code At least and very good. 1 Using System; 2 Using System. runtime. interopservices; 3 Using System. text; 4 Using System. net; 5 6 Namespace Nexplus. nsiter 7
Is there something in php equivalent to CookieContainer in Asp. Net? In Asp. Net, the following functions can be used to access the page. postData is the data that requires the Post of the specified url:
Public string getHtml (string url, CookieContainer cookie, byte [] postData );
How to implement it in php? Can it be written like this?
Are there any of the following statements?
Curl_setopt
session to be retrieved later. To do this, follow these steps:
Create a new ASP. NET web application using Visual C #. net. Name cookiecontainerapp of the project.By default, webform 1. aspx is created.
InDesignRight-clickWebform 1And then clickView HTML sources.
Replace the existing code with the following code:
Right-click Solution ExplorerReferenceAnd then clickAdd web reference.
InAddressThe following url is entered in the text box: http: // localhost/webservice1/service1.asmx
ClickP
Public
Static List getallcookies (cookiecontainer CC)
{
List lstcookies =
New List ();
Hashtable table = (hashtable) CC. GetType (). invokemember ("M_domaintable",System. reflection. bindingflags. nonpublic | system. reflection.
methods on the Web browser.2. Because of the use of form verification, and prohibit anonymous access, resulting in the inability to properly reference the service, because the service reference is also an HTTP request, the default is not logged in the case, you refer to the limited service address, it will automatically jump to the login service address, so in response to this problem, I used two ways, The first is: Do not prohibit anonymous access, when the service reference succeeds, plus the
The download of many websites involves user verification, so that the convenient WebClient. Download Method in the past cannot request the target data. Httpwebrequest. getresponse is not supported.
Here, two available verification downloads are provided for the two components. The idea is to use webbrowser to obtain cookie information and construct a valid cookie to pass it to the two components to provide download permissions.
The implementation of httpwebrequest is relatively easy, because htt
To use session in webservice, 1. you must add the [WebMethod (EnableSession = true)] modifier to the server method. on the client, a new CookieContainer () must be instantiated for its CookieContainer after the webservice proxy class is instantiated to use the session storage state. 3. in addition, as long as multiple webservice proxies contain the same cookie, the same session can be shared. The cookie is
pressing the Login button, you can press GetName to get the name you just entered.However, if we create another website and add a web reference to call the webservice we just compiled, the problem arises, the GeName method does not get the username we just logged on to (if you call this method in winform, the same problem will occur ). Is this method not feasible?Otherwise, we can assign a value to CookieContainer of the WebService. Modify the Sessio
class
Using System; using System. collections. generic; using System. linq; using System. text; using System. net; using System. IO; using System. threading; namespace WpfUI {public class HTMLHelper {////// Obtain the CooKie ///////////////
Public static CookieContainer GetCooKie (string loginUrl, string postdata, HttpHeader header) {HttpWebRequest request = null; HttpWebResponse response = null; try {CookieCon
to have ended. After logging the user name by pressing the login button, you can press getname to get the name you just entered.
However, if we create another website and add a web reference to call the WebService we just compiled, the problem arises, the gename method does not get the username we just logged on to (if you call this method in winform, the same problem will occur ). Is this method not feasible?
Otherwise, we can assign a value to the cookiec
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.