Click here to Skip to main content
15,900,108 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
i got a small piece of problem hope you can help me out.

basically. i know how to do the login in different sites using httpwebrequest..

but now, i was working with something like. i am trying to comment to one of my wordpress website,

VB
Dim postData As String = "author=" & txtUser.Text & "&email=" & txtEmail.Text & "&url=" & txtWebsite.Text & "&comment=" & txtMessage.Text & "&submit=&comment_post_ID=" & stringA
        Dim tempcookies As New CookieContainer
        Dim encoding As New UTF8Encoding
        Dim byteData As Byte() = encoding.GetBytes(postData)
        Dim postreq As HttpWebRequest = DirectCast(HttpWebRequest.Create("http://www.myurl.com/wp-comments-post.php"), HttpWebRequest)
        postreq.Method = "POST"
  
        postreq.KeepAlive = True
        postreq.CookieContainer = tempcookies
        postreq.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"
        postreq.ContentType = "application/x-www-form-urlencoded"
        postreq.Referer = "url"
        postreq.ContentLength = byteData.Length
        Dim postreqstream As Stream = postreq.GetRequestStream()
        postreqstream.Write(byteData, 0, byteData.Length)
        postreqstream.Close()
        Dim postresponse As HttpWebResponse
        postresponse = DirectCast(postreq.GetResponse, HttpWebResponse)
        tempcookies.Add(postresponse.Cookies)


but i am stuck with the post respone i'm getting an error of.
The remote server returned an error: (500) Internal Server Error.

but when I will try to login in wordpress, with the format of login post data.. it logs me,

This is the one you can see on LiveHttpHeaders

VB
'author=a57rf&email=abcdefg%40yahoo.com&url=http%3A%2F%2Fyah.com&comment=xxxxxx+sample&submit=&comment_post_ID=8

 
'if I substitute the values to my variables like below, it gives me an error 500, Internal Server Error

Dim postData As String = "author=" & txtUser.Text & "&email=" & txtEmail.Text & "&url=" & txtWebsite.Text & "&comment=" & txtMessage.Text & "&submit=&comment_post_ID=" & stringA


tried to remove the &comment_post_ID , it woudn't give me an error, but it doesnt give me a result also, its like a blank result.


the referURL, is originally a url, i just substitute it temporarily as "url", but its really a url inside

do you have an idea how to tweak this?
Posted
Updated 13-Oct-11 18:15pm
v2
Comments
DaveAuld 13-Oct-11 13:11pm    
Have you looked at the developer API's over @ wordpress, doing a quick search in google shows up they use XML-RPC and there are various docs available. I suggest you go start reading and searching........
Sergey Alexandrovich Kryukov 13-Oct-11 17:20pm    
"It won't" what? You need to explain your problem exactly. HttpWebRequest is well described in regular MSDN help pages, with code samples, used by many. What's wrong?
--SA
aron quiray 14-Oct-11 0:16am    
i have updated the question. hope you get my problem. thanks!

If you are open to use opensource for your purpose you can use following WordpressWrapper in c#. It uses wordpress api underneath.

Alternatively, you can keep this as reference and write some code yourself.

HttpWebRequest is best in many cases, however it would be easier to use wordpress api's than HttpWebRequest.

http://joeblogs.codeplex.com/[^]
http://www.alexjamesbrown.com/development/using-joeblogs/[^]
 
Share this answer
 
v2
Comments
aron quiray 14-Oct-11 5:13am    
Wordpress Wrapper will work for sure, but the problem is.. what if I wanted to post in other blogsites? i don't have an account at their sites right. are there any methods for this?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900