Wordpress HttpWebrequest vb.net -


i trying code self bot stuff me on self hosted wordpress blogs, managed login using webrequests had problems solved them. i'm trying go permalinks page example data when im trying using login cookie redirects me login page i'm not using login cookie.

so login function:

 cleanurl = textbox3.text     logincookie = new cookiecontainer      dim url string = cleanurl & "/wp-login.php"     dim postreq httpwebrequest = directcast(httpwebrequest.create(url), httpwebrequest)     dim cookies new cookiecontainer      postreq.cookiecontainer = cookies     postreq.useragent = "mozilla/5.0 (windows nt 6.1; wow64; rv:2.0b6pre) gecko/20100903 firefox/4.0b6pre"     postreq.keepalive = true     postreq.timeout = 120000     postreq.method = "post"     postreq.referer = url      postreq.allowautoredirect = false     postreq.contenttype = "application/x-www-form-urlencoded"      dim postdata string = "log=" & textbox1.text & "&pwd=" & textbox2.text & "&wp-submit=log+in&redirect_to=" & cleanurl & "/wp-admin" & "&testcookie=1"     dim encoding new utf8encoding     dim bytedata byte() = encoding.getbytes(postdata)     postreq.contentlength = bytedata.length         dim postreqstream stream = postreq.getrequeststream()     postreqstream.write(bytedata, 0, bytedata.length)     postreqstream.close()      dim postresponse httpwebresponse     postresponse = directcast(postreq.getresponse, httpwebresponse)       '/ following set next request authentication cookie      dim nextreq httpwebrequest = directcast(httpwebrequest.create(cleanurl), httpwebrequest)     nextreq.contenttype = "application/x-www-form-urlencoded"     nextreq.method = "get"     nextreq.cookiecontainer = new cookiecontainer      nextreq.cookiecontainer.add(postresponse.cookies)       nextreq.useragent = "mozilla/5.0 (windows nt 6.1; wow64; rv:2.0b6pre) gecko/20100903 firefox/4.0b6pre"     nextreq.keepalive = true      dim nextresponse httpwebresponse     nextresponse = directcast(nextreq.getresponse, httpwebresponse)      logincookie = nextreq.cookiecontainer     logincookie.add(nextresponse.cookies)        dim postreqreader new streamreader(nextresponse.getresponsestream())     dim thepage string = postreqreader.readtoend      nextresponse.close()      richtextbox1.text = thepage     webbrowser1.documenttext = thepage     refresh()      if thepage.contains("error")         msgbox("error logging in!")     else         msgbox("lets start blogging!")      end if 

it works perfect, gets me url homepage , shows me im logged in. when im launching code permalinks edit page returns login page source code means wasn't able login.

dim nextreq httpwebrequest = directcast(httpwebrequest.create(cleanurl & "/wp-admin/options-permalink.php"), httpwebrequest)     nextreq.contenttype = "application/x-www-form-urlencoded"     nextreq.method = "get"     nextreq.cookiecontainer = logincookie        nextreq.useragent = "mozilla/5.0 (windows nt 6.1; wow64; rv:2.0b6pre) gecko/20100903 firefox/4.0b6pre"     nextreq.keepalive = true       dim nextresponse httpwebresponse = directcast(nextreq.getresponse, httpwebresponse)      nextreq.cookiecontainer.add(nextresponse.cookies)        dim postreqreader new streamreader(nextresponse.getresponsestream())     dim thepage string = postreqreader.readtoend      nextresponse.close()      richtextbox1.text = thepage     webbrowser1.documenttext = thepage     refresh() 

here alternative. try wordpress api (xmlrpc.php) access , modify data in wordpress installation. have used cookcomputing.xmlrpc achieve this.

here sample on how create new wordpress post:

imports cookcomputing.xmlrpc  public sub add_new_post_sample()     dim newpostcontent new newpostcontent     newpostcontent.post_type = "post"     newpostcontent.post_status = "draft"     newpostcontent.post_title = "mytitle"     newpostcontent.post_author = "1"     newpostcontent.post_excerpt = ""     newpostcontent.post_content = "mycontent"     newpostcontent.post_date_gmt = "2015-01-21 00:00:00"     newpostcontent.post_name = "my-unique-url"     newpostcontent.post_password = ""     newpostcontent.comment_status = "closed"     newpostcontent.ping_status = "closed"     newpostcontent.sticky = false     newpostcontent.post_thumbnail = 0     newpostcontent.post_parent = 0     newpostcontent.mycustom_fields = new string() {""}      dim api = directcast(xmlrpcproxygen.create(gettype(igetcatlist)), igetcatlist)      dim clientprotocal = directcast(api, xmlrpcclientprotocol)     clientprotocal.url = "http://myurl.com/xmlrpc.php"      dim result string = api.newpost(1, "admin", "password", newpostcontent)      console.writeline(result) end sub  public structure newpostcontent     public post_type string     public post_status string     public post_title string     public post_author integer     public post_excerpt string     public post_content string     public post_date_gmt datetime     public post_name string     public post_password string     public comment_status string     public ping_status string     public sticky boolean     public post_thumbnail integer     public post_parent integer     public mycustom_fields string() end structure 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -