...or kill me, because I'm not going to get any sleep until I get this resolved.
'Sigh
Kay I have been dealing with this code all day. I'm trying to make a remote wordpress tool that I can use for things like blog automation, user approval etc.
I'll be honest this is code that I received from a friend...BUT I'VE HAD THE HARDEST TIME EVER WITH IT. :eek: I was getting a cookies blocked error which I fixed. Some other errors too:confused:I can't even remember now. These past 2 days have been a friggin' blur.
I was able to hold off asking any questions until about 2 hours ago, and of course the solution was the an obvious omission of a separation character(this can't be programmer life). Thank you Paxic from SOF for that. And of course I got all excited, but noticed that the program immediately directs back to the log in screen and the reason seems to be that the wp-settings are not being included in the cookie container.
I hope that I haven't lost you.
When I look through my Fiddler program I notice that these wp-settings seem to be a constant remaining non changing item in the Cookie/Login data. Initially tried appending the data in "settings"(line 9) to postData(line 8). Then I thought it would be just easiest to include it with tempcookies, but everytime I try to add settings in any kind of way I get an error that says the +, or &, or Comma is not a valid operator for System.Net.CookieContainer. I just want to add the settings to the CookieContainer! Can anyone help me?
'Sigh
Kay I have been dealing with this code all day. I'm trying to make a remote wordpress tool that I can use for things like blog automation, user approval etc.
I'll be honest this is code that I received from a friend...BUT I'VE HAD THE HARDEST TIME EVER WITH IT. :eek: I was getting a cookies blocked error which I fixed. Some other errors too:confused:I can't even remember now. These past 2 days have been a friggin' blur.
I was able to hold off asking any questions until about 2 hours ago, and of course the solution was the an obvious omission of a separation character(this can't be programmer life). Thank you Paxic from SOF for that. And of course I got all excited, but noticed that the program immediately directs back to the log in screen and the reason seems to be that the wp-settings are not being included in the cookie container.
I hope that I haven't lost you.
Code:
Imports System.Text
Imports System.Net
Imports System.IO
Public Class Form1
Dim logincookie As CookieContainer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim postData As String = "log=" & TextBox1.Text & "&pwd=" & TextBox2.Text & "&wp-submit=Log+In&redirect_to=http://csvlife.com/wp-admin/" & "&wordpress_test_cookie=WP+Cookie+check"
Dim settings As String = "&wp-settings-1=editor%3Dtinymce%26hidetb%3D1%26imgsize%3Dmedium" & "&wp-settings-time-1=1356584922"
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://csvlife.com/wp-login.php"), HttpWebRequest)
postreq.Method = "POST"
postreq.KeepAlive = True
postreq.AllowAutoRedirect = True
postreq.CookieContainer = tempcookies
postreq.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:2.0b6pre) Gecko/20100903 Firefox/4.0b6pre"
postreq.ContentType = "application/x-www-form-urlencoded"
postreq.Referer = "http://csvlife.com/wp-login.php?redirect_to=http%3A%2F%2Fcsvlife.com%2Fwp-admin%2F&reauth=1"
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)
logincookie = tempcookies
Dim postreqreader As New StreamReader(postresponse.GetResponseStream())
Dim thepage As String = postreqreader.ReadToEnd
If thepage.Contains("ERROR") Then
MsgBox("Error logging in!")
Else
MsgBox("Your Logged In!")
End If
End Sub
End Class