Recently, I received a task to invite friends on the kaixin.com SNS website.
After checking some information, I found more examples of using PHP or Java. Few. Net C.
Refer to their example. I wrote a webrequest, httpwebrequest, webresponse, and httpwebresponse for the application. net.
My personal experience: the login mailbox is different, and the analysis path should be patient. For the HTTP connection, you need to obtain the httpheader and then send it back. There is an example in the compressed package (including the source code ).
If you are interested, you can mail me Dev. guyan # gmail.com If You Are the One.
PS...> _ <The csdn resource upload always says the verification code is incorrect ....
Paste a piece of main code
Private string getrequesthtml (string URL, encoding encodeing, reqmethod rmethod)
{
String html = string. empty;
Try
{
Req = (httpwebrequest) webrequest. Create (URL );
Req. allowautoredirect = true;
Req. cookiecontainer = cookiecon;
Req. Credentials = credentialcache. defaultcredentials;
Req. method = rmethod. tostring ();
Req. contenttype = "application/X-WWW-form-urlencoded ";
Req. useragent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; gtb5; Mozilla/4.0 (compatible Mozilla/4.0 (compatible-embeddedwb 14.59 http://bsalsa.com/embeddedwb-14.59 from: http://bsalsa.com/; Server Load balancer ;. net CLR 2.0.50727; Media Center PC 5.0; infopath.2 ;. net CLR 3.5.30729 ;. net CLR 3.0.30618; CBA )";
Res = (httpwebresponse) Req. getresponse ();
If (cookieheader. Equals (string. Empty ))
{
Cookieheader = Req. cookiecontainer. getcookieheader (New uri (URL ));
}
Else
{
Req. cookiecontainer. setcookies (New uri (URL), cookieheader );
}
Html = new StreamReader (res. GetResponseStream (), EnCodeing). ReadToEnd ();
}
Catch (Exception ex)
{
Html = ex. Message;
}
Return html;
}
Private string GetRequestHtml (string URL, Encoding EnCodeing, ReqMethod RMethod)
{
String html = string. empty;
Try
{
Req = (httpwebrequest) webrequest. Create (URL );
Req. allowautoredirect = true;
Req. cookiecontainer = cookiecon;
Req. Credentials = credentialcache. defaultcredentials;
Req. Method = RMethod. ToString ();
Req. ContentType = "application/x-www-form-urlencoded ";
Req. userAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; GTB5; Mozilla/4.0 (Compatible Mozilla/4.0 (Compatible-EmbeddedWB 14.59 http://bsalsa.com/EmbeddedWB-14.59 from: http://bsalsa.com/; Server Load balancer ;. net clr 2.0.50727; Media Center PC 5.0; InfoPath.2 ;. net clr 3.5.30729 ;. net clr 3.0.30618; CBA )";
Res = (HttpWebResponse) req. GetResponse ();
If (cookieheader. Equals (string. Empty ))
{
Cookieheader = req. CookieContainer. GetCookieHeader (new Uri (URL ));
}
Else
{
Req. CookieContainer. SetCookies (new Uri (URL), cookieheader );
}
Html = new streamreader (res. getresponsestream (), encodeing). readtoend ();
}
Catch (exception ex)
{
Html = ex. message;
}
Return HTML;
}
Source code download: http://www.rssink.com/Temp/GetEmailContacts.rar
From: http://blog.csdn.net/skylen/archive/2009/03/27/4028906.aspx