Recent work has been about simulating HTTP request knowledge.
Originally thought very simple, is simply simulates the HTTP request. Use Fiddler to simulate the request, verify that the interface is available, and then go directly to the code.
But in the simulation of a Unicom HTTP request, I encountered difficulties, the first to enter the other people's website, must be registered account login.
So the previous simple login at all does not involve what the cookie parameter, there is also a very simple single key value pairs assignment.
I cut a request for Unicom:
You can see the cookie for this request is quite long; my first show was 艹 so long. Those that are useful are useless, do not want me to try one by one, it is better to be assigned to the value on the back,
So I'll put all the cookies
Req. Cookiecontainer.add (New Cookie ("Sid", "WERWERQW", "/", "iservice.10010"));
This form plus finally since the error.
I wonder if this interface is encrypted, or is not connected at all. If I put all the requests into the fiddler to try, the result is still not,
Is the interface really not available, should not AH!
I have tried to use postman to request, there is a result (it seems that the analog HTTP request postman is better than fiddler)
So why is my code not working?
Thought for a while, I know the problem must be on the cookie;
It is best to use reflection to assign a value to the cookie so that it is simple and practical, the code is as follows:
1 Public Static voidSetheadervalue (webheadercollection header,stringNamestringvalue)2 {3 varproperty =typeof(webheadercollection). GetProperty ("innercollection", BindingFlags.Instance |bindingflags.nonpublic);4 if(Property! =NULL)5 {6 varCollection = property. GetValue (header,NULL) asNameValueCollection;7Collection[name] =value;8 }9}
Setheadervalue (req. Headers, "Cookie", "value of the Cookie");
It's OK!
About the assignment of a simulated HTTP request cookie