开发者

Post Comment on wordpress Blogs

I was working on a project in which I have to post comment on by wordpress 开发者_JAVA百科blog that should contain the text user entered in text box.I have been trying to user HttpWebRequestbut it fails and returns 404 not found. Even the link is not broken.here is my code

fore test purpose i have hard coded the entries in string post

 string post = "author=" + HttpUtility.UrlEncode("afnan") + "&email=" + HttpUtility.UrlEncode("ifi@ifi.com") + "&url=" + HttpUtility.UrlEncode("abcd.com") +
                    "&comment=" + HttpUtility.UrlEncode("no comments");
                HttpWebRequest wrWebRequest = WebRequest.Create("http://testing.autoprofitbot.com/blogtest/2011/05/13/call-3-computer-repair-services-put-to-test-4/wp-comments-post.php?") as HttpWebRequest;

                wrWebRequest.Method = "POST";
                wrWebRequest.ContentLength = post.Length;
                wrWebRequest.ContentType = "application/x-www-form-urlencoded";
                wrWebRequest.CookieContainer = new CookieContainer();

                //// Post to the login form.
                StreamWriter swRequestWriter = new
                StreamWriter(wrWebRequest.GetRequestStream());
                swRequestWriter.Write(post);
                swRequestWriter.Close();

                // Get the response.
                HttpWebResponse hwrWebResponse =
                (HttpWebResponse)wrWebRequest.GetResponse();

                // Have some cookies.
                CookieCollection ccCookies = hwrWebResponse.Cookies;

                // Read the response
                StreamReader srResponseReader = new
                StreamReader(hwrWebResponse.GetResponseStream());
                string strResponseData = srResponseReader.ReadToEnd();
                srResponseReader.Close();
                webBrowser1.DocumentText = strResponseData;


There are 3 problems with your code:

  1. the post data lacks 2 parameters
  2. the WebRequest.Create is not correct
  3. the referrer url is missing; use livehttpheaders or httpfox to get the correct headers format!
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜