locked
Http Post request through Httpwebrequest To forum RRS feed

  • Question

  • Hi.. sorry for my english but i'm italian... I'm creating an app that edit a post in a ipforum with httpwebrequest and httpwebresponse in vb.net... I use fiddler2 to get the post forms... I successfully create  the code to connect to the site... the authentication works well and i don't found problems... But to edit a post i don't find how to do it...
     this is the request of the site taken from fiddler:

     

    POST http://site.com/download/index.php?&app=forums&module=ajax&section=topics&do=editBoxSave&p=499632&t=103273&f=129 HTTP/1.1
    Accept: text/javascript, text/html, application/xml, text/xml, */*
    Accept-Language: it
    x-prototype-version: 1.6.1
    Referer: http://site.com/download/index.php?/topic/103273-gary-unmarried-season-2-1717/#entry499632
    x-requested-with: XMLHttpRequest
    Content-Type: application/x-www-form-urlencoded; charset=iso-8859-1
    Accept-Encoding: gzip, deflate
    User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2;
    
    
    .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2;
    
    
    OfficeLiveConnector.1.4; OfficeLivePatch.1.3)
    Host: site.com
    Content-Length: 153
    Connection: Keep-Alive
    Pragma: no-cache
    Cookie: some cookiedata
    
    md5check=d45d8f6f7a9aa4d1b0a169b7e4efdb6a&Post=Aggiunto%2520video%2520e%2520sottotitoli%2520episodio%252017
    
    
    &add_edit=&post_edit_reason=&post_htmlstatus=0
    HTTP/1.1 200 OK
    Server: nginx/0.4.13
    Date: Thu, 18 Mar 2010 21:33:43 GMT
    Content-Type: application/json;charset=ISO-8859-1
    Connection: close
    X-Powered-By: PHP/5.2.8
    Cache-Control: no-cache, must-revalidate, max-age=0
    Expires: 0
    Pragma: no-cache
    Content-Length: 181
    
    {"successString":"Aggiunto video e sottotitoli episodio 17\n    
    
    
    \n\t<br \/>\n\t<p class='edit'>\n\t\t\tMessaggio modificato da <b>user<\/b> il Oggi, 10:33 PM\n\t\t\t\n\t\t<\/p>"}

    I write this code to do the webrequest:

     

            request1 = CType(WebRequest.Create("http://site.com/download/index.php?&app=forums&module=ajax" & _ 
            "&section=topics&do=editBoxSave&p=" & npost & "&t=" & ntopic & "&f=129"), HttpWebRequest)
            s = "md5check=d45d8f6f7a9aa4d1b0a169b7e4efdb6a&Post=Aggiunto%2520video%" _
            "2520e%2520sottotitoli%2520episodio%252017&add_edit=&post_edit_reason=&post_htmlstatus=0"
            request1.Method = WebRequestMethods.Http.Post
            request1.ContentType = "application/x-www-form-urlencoded"
            Dim data = System.Text.Encoding.UTF8.GetBytes(s)
            request1.ContentLength = data.Length
    
            Dim str As IO.Stream = request1.GetRequestStream
            str.Write(data, 0, data.Length)
            str.Close()
            request1.KeepAlive = True
            request1.CookieContainer = c
            request1.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727;" & _"
            ".NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; OfficeLiveConnector.1.4; OfficeLivePatch.1.3)"
            Try
                response1 = request1.GetResponse
    
            Catch webex As Net.WebException
                MsgBox(webex.Message.ToString)
                Exit Sub
            Catch ex As Exception
                MsgBox(ex.Message.ToString)
                Exit Sub
            End Try
            If response1.StatusCode = HttpStatusCode.OK Then
                tmp = (New IO.StreamReader(response1.GetResponseStream())).ReadToEnd
                Dim fw As New IO.StreamWriter("D:\Desktop\z.htm", False)
                fw.Write(tmp)
                fw.Close()
            Else
                MsgBox("Problemi di connessione al sito...")
                Exit Sub
            End If

    naturally in c (a cookiecontainer) contains the cookies of the successful login.. did you see what is the problem? because i can't understand what is it :(

    Friday, March 19, 2010 2:02 PM

All replies