Question Help saving html file on server

learnerguy

Member
Joined
Jul 28, 2013
Messages
20
Programming Experience
Beginner
Hi,

I want to be able to update an html file through my application. I get the source code of the website using webclient I tried to post the data once edited using the following I found on the net trying to figure out how to do this.(I am rather new at this stuff)
Function WDRequest(URL As String, method As String, POSTdata As String) As String 
       Dim responseData As String = ""
        Try
            Dim hwrequest As Net.HttpWebRequest = Net.WebRequest.Create(TextBox2.Text)
            hwrequest.Accept = "*/*"
            hwrequest.AllowAutoRedirect = True
            hwrequest.UserAgent = "http_requester/0.1"
            hwrequest.Timeout = 60000
            hwrequest.Method = method
            If hwrequest.Method = "POST" Then
                hwrequest.ContentType = "application/x-www-form-urlencoded"
                Dim encoding As New ASCIIEncoding() 'Use UTF8Encoding for XML requests
                Dim postByteArray() As Byte = encoding.GetBytes(POSTdata)
                hwrequest.ContentLength = postByteArray.Length
                Dim postStream As IO.Stream = hwrequest.GetRequestStream()
                postStream.Write(postByteArray, 0, postByteArray.Length)
                postStream.Close()
            End If
            Dim hwresponse As Net.HttpWebResponse = hwrequest.GetResponse()
            If hwresponse.StatusCode = Net.HttpStatusCode.OK Then
                Dim responseStream As IO.StreamReader = _
                  New IO.StreamReader(hwresponse.GetResponseStream())
                responseData = responseStream.ReadToEnd()
            End If
            hwresponse.Close()
        Catch ex As Exception
            responseData = "An error occurred: " & ex.Message
        End Try
        Return responseData
    End Function


I then tell the program to post the info using
WDRequest("textbox2.text", "POST", "rtbdoc.text")


Where textbox2.text is the url the user entered and rtbdoc.text is the source of the html file.
I am not understanding, why is it not posting back the file?can someone please help me solve this. I am obviously doing it wrong
thanks a lot for your time
-Learnerguy
 
Last edited by a moderator:
Are you saying that you want to send data to a web application or that you actually want to replace an existing HTML file on the web server? Posting to a URL does not write a file to that location, which might not even correspond to a file. If you want to upload a file to a web server, either the web application would have to provide a function to accept the contents of a file save it somewhere or you'd have to use FTP. Even if the web application did accept an upload, it would be very rare that it would actually overwrite part of the application itself because that would be a huge security hole. Content-management systems offer something like that but, even then, only for additional content pages and not for the core application itself.
 
Hi Mr. Mcilhinney. OH! Sometimes can't see the forest for the trees. No wonder it won't update the file it has to be re-sent. ok thanks I appreciate your time in answering what seems to be a rather foolish question

Thanks again and have a great day!
-Learnerguy
 
Back
Top