使用httpwebrequest发布状态Facebook。 [英] Post status Facebook using httpwebrequest.

查看:67
本文介绍了使用httpwebrequest发布状态Facebook。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<form method="post" action="/composer/mbasic/?csid=081bb362-bad2-4221-aabe-0d4a8cdf7447&incparms%5B0%5D=xc_message&av=10000" 
enctype="multipart/form-data">
<input type="hidden" name="fb_dtsg" value="AQHr-SSfZsAV" autocomplete="off" />
<input type="hidden" name="charset_test" value="€,´,€,´,水,Д,Є" />
<input type="hidden" name="at" />
<input type="hidden" name="target" value="10000" />
<input type="hidden" name="csid" value="081bb362-bad2-4221-aabe-0d4a8cdf7447" />
<input type="hidden" name="c_src" value="feed" />
<input type="hidden" name="referrer" value="feed" />
<input type="hidden" name="ctype" value="advanced" />
<input type="hidden" name="cver" value="amber" />
<input type="hidden" name="users_with" />
<input type="hidden" name="album_id" />
<input type="hidden" name="waterfall_source" value="advanced_composer_feed" />
<input type="hidden" name="privacyx" value="300645083384735" />
<span class="bc">Share with: <label class="bd be bf"><input value="Public" type="submit" name="view_privacy" class="bg bh be" />
<div class="bi"></div></label></span><div class="bj"><table class="l z bk bl"><tbody><tr><td class="n bm"><label for="u_0_0">
<img src="https://fbcdn-profile-a.akamaihd.net/hprofile-ak-frc3/v/t1.0-1/c5.0." width="32" class="bn s" alt="" /></label>
</td><td class="t m">
<textarea class="bo bp bq" name="xc_message" id="u_0_0" rows="3"></textarea>
</td></tr></tbody></table></div><div class="br"><div class="bs bt"><table class="l bu m"><tbody><tr><td class="bv n"><label for="u_0_1" class="bw">
<img src="https://fbstatic-a.akamaihd.net/rsrc.php/v2/yE/r/Q-U_WZzAqVP.png" width="16" height="16" class="bx by s" /></label></td><td class="bv n">
<input value="Tag Friends" type="submit" name="view_withtag" class="bz ca cb" id="u_0_1" /></td></tr></tbody></table></div><div class="bs bt">
<table class="l bu m"><tbody><tr><td class="bv n"><label for="u_0_2" class="bw">
<img src="https://fbstatic-a.akamaihd.net/rsrc.php/v2/yW/r/gqS520QVYNv.png" width="16" height="16" class="bx by s" /></label></td><td class="bv n">
<input value="Add Location" type="submit" name="view_location" class="bz ca cb" id="u_0_2" /></td></tr></tbody></table></div><div class="bs bt">
<table class="l bu m"><tbody><tr><td class="bv n"><label for="u_0_3" class="bw">
<img src="https://fbstatic-a.akamaihd.net/rsrc.php/v2/ym/r/s_JBnFooj2Z.png" width="16" height="16" class="bx by s" /></label></td><td class="bv n">
<input value="Add Feeling or Activity" type="submit" name="view_minutiae" class="bz ca cb" id="u_0_3" /></td></tr></tbody></table></div><div class="bs bt">
<table class="l bu m"><tbody><tr><td class="bv n"><label for="u_0_4" class="bw">
<img src="https://fbstatic-a.akamaihd.net/rsrc.php/v2/y1/r/KIY954HBjri.png" width="16" height="16" class="bx by s" /></label></td><td class="bv n">
<input value="Add Photos" type="submit" name="view_photo" class="bz ca cb" id="u_0_4" /></td></tr></tbody></table></div></div>
<input value="Post" type="submit" name="view_post" class="cc cd ce cf cg" /></form>





i需要将状态facebook发布到我的墙上。但是,我不......请帮助我!

这里,我的代码来自: m.Facebook with C#







i need post status facebook in to my wall. but, i do not.. please help me!
here , my code from : m.Facebook with C#


public bool UpdateStatus2(string txt, string url, CookieCollection cok)
        {

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.CookieContainer = new CookieContainer();
            request.CookieContainer.Add(cok);
            request.UserAgent = userAgent;
            request.KeepAlive = true;
            request.Timeout = 45000;

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            cok.Add(response.Cookies);

            StreamReader sr = new StreamReader(response.GetResponseStream());

            string mainHTML = sr.ReadToEnd();
            string html = mainHTML;//.Replace(""", "\"");
            //html = html.Replace(@"\/", "/");
            //html = html.Replace(@"\u0025", "%");
            //html = html.Replace("&", "&");
            //html = html.Replace(""", "\"");

            if (html.Contains("id=\"root"))
            {
                //html = html.Substring(html.IndexOf("id=\"root"));
                Regex regAct = new Regex("action=\"(/composer/mbasic/[^\"]+?)\"");
                Match matAct = regAct.Match(html);
                string action = "https://m.facebook.com" + (matAct.Groups[1].Value).Replace("&", "&");

                //html = html.Remove(html.IndexOf("form>"));

                Regex reg = new Regex(@"name=""([^""]+)"" value=""([^""]+)""");
                MatchCollection mc = reg.Matches(html);

                string postData = "";
                List<string> names = new List<string>() { "fb_dtsg", "charset_test", "target" };
                if (url.Contains("/home.php"))
                    names.RemoveRange(2, 2);
                List<string> values = new List<string>();

                for (int k = 0; k < mc.Count; k++)
                {
                    //if (mc[k].Groups[1].Value.Contains("charset_test"))
                    {
                        
                        postData += mc[k].Groups[1].Value + "=" +HttpUtility.UrlEncode(mc[k].Groups[2].Value) + "&";
                    }
                    //else
                    //    postData += HttpUtility.UrlEncode(mc[k].Groups[1].Value) + "=" +HttpUtility.UrlEncode(mc[k].Groups[2].Value) + "&";
                }
                //postData += "at=" + HttpUtility.UrlEncode(txt);
                //postData += "users_with=" + HttpUtility.UrlEncode(txt);
                //postData += "album_id=" + HttpUtility.UrlEncode(txt);
                postData += "status=" + HttpUtility.UrlEncode(txt);

                HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(action);
                getRequest.CookieContainer = new CookieContainer();
                getRequest.CookieContainer.Add(cok); //recover cookies First request
                getRequest.Method = WebRequestMethods.Http.Post;
                getRequest.UserAgent = userAgent;// "Mozilla/5.0 (Windows; U; Windows NT 6.1; ru; rv:1.9.2.3) Gecko/20100401 Firefox/4.0 (.NET CLR 3.5.30729)";//userAgent;//
                getRequest.AllowWriteStreamBuffering = true;
                getRequest.ProtocolVersion = HttpVersion.Version11;
                getRequest.KeepAlive = false;
                getRequest.AllowAutoRedirect = false;
                ////getRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
                getRequest.ContentType = "application/x-www-form-urlencoded;charset=TF-8;";
                getRequest.Referer = "https://m.facebook.com/";
                //getRequest.Referer = url;
                byte[] byteArray = Encoding.ASCII.GetBytes(postData);
                getRequest.ContentLength = byteArray.Length;
                Stream newStream = getRequest.GetRequestStream(); //open connection
                newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
                newStream.Close();



                HttpWebResponse getResponse = (HttpWebResponse)getRequest.GetResponse();
                cok.Add(getResponse.Cookies);
                //UpdateStatus1(txt, getResponse.ResponseUri.ToString(), cok);
                return true;
            }
            return false;
        }

推荐答案

问题来自cookie。登录后facebook发布新的cookie动作。你可以在服务器的bz包响应中找到它。
The problem come from cookie. After login facebook release new cookie for actions. You can find it out in bz package response from server.


这篇关于使用httpwebrequest发布状态Facebook。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆