Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在wordpress博客上发表评论_Wordpress_Post_C# 4.0_Httpwebrequest - Fatal编程技术网

在wordpress博客上发表评论

在wordpress博客上发表评论,wordpress,post,c#-4.0,httpwebrequest,Wordpress,Post,C# 4.0,Httpwebrequest,我在做一个项目,在这个项目中,我必须通过wordpress博客发表评论,其中应该包含文本框中输入的文本用户。我一直在尝试用户HttpWebRequest,但失败并返回404 not found。连链接都没有断。这是我的代码 出于测试目的,我已在string post string post = "author=" + HttpUtility.UrlEncode("afnan") + "&email=" + HttpUtility.UrlEncode("ifi@ifi.com") + "

我在做一个项目,在这个项目中,我必须通过wordpress博客发表评论,其中应该包含文本框中输入的文本用户。我一直在尝试用户
HttpWebRequest
,但失败并返回404 not found。连链接都没有断。这是我的代码

出于测试目的,我已在
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;

您的代码有3个问题:

  • post数据缺少2个参数
  • WebRequest.Create
    不正确
  • 缺少引用者url;使用
    livehttpheaders
    httpfox
    获取正确的头格式
    你能举一个例子来演示简单的表单发布感谢吗