none
Post File HTTP using visual foxpro

    Question

  • Hello all,

    I'm not sure if anyone is familiarized with a open source program called "HFS Http File Server" for those of you that are I am trying to post upload a file using some code I found in Google. However I cant seem to get it to work. The furthest I get is
    a response in HFS with the Post upload request however the upload never begins below is the code I have so far

    filname = FileToStr("Movies.txt")
    loHTTP = CREATEOBJECT("WinHttp.WinHttpRequest.5.1")    
    loHTTP.Open("POST", "http://myip:8080/upload/", .F.)
    loHTTP.SetRequestHeader("content-type", "application/x-www-form-urlencoded")
    loHTTP.Send(filname)

    any help is greatly appreciated




    Sunday, April 24, 2016 2:20 AM

Answers

  • Try like this:

    filecontent = FileToStr("Movies.txt") loHTTP = CREATEOBJECT("WinHttp.WinHttpRequest.5.1") loHTTP.Open("POST", "http://myip:8080/upload/", .F.) loHTTP.SetRequestHeader("content-type", "text/plain") && or other mime types for other file types.
    loHTTP.SetRequestHeader("content-disposition", 'attachment; filename="Movies.txt"')
    loHTTP.Send(filecontent)

    Bye, Olaf.

    With content-type application/x-www-form-urlencoded you indicate you send form data, which would need some more sections in the body you finally send. As you just send a file the content-type has to be the files html mime type.

    If you want to stay with application/x-www-form-urlencoded, ie the HFS server expects a form submit, you have to go the route using fiddler to see how it's done, or you can read through several RFC documents.


    Olaf Doschke - TMN Systemberatung GmbH

    http://www.tmn-systemberatung.de



    Sunday, April 24, 2016 2:15 PM

All replies

  • I'm unsure, if the content-type header would be that way. Download and run Fiddler, a tool to monitor http protocol messages between any client (browser, your app) and the internet/proxies/network. 

    Then observe a normal file upload done via html file element: <input type="file" name="somename"> in a html form, that uses enctype="multipart/form-data".

    You'll see what headers the browser sets for submitting this form data, I'm pretty sure it would be more than one header.

    Bye, Olaf.


    Olaf Doschke - TMN Systemberatung GmbH

    http://www.tmn-systemberatung.de



    Sunday, April 24, 2016 5:06 AM
  • Try like this:

    filecontent = FileToStr("Movies.txt") loHTTP = CREATEOBJECT("WinHttp.WinHttpRequest.5.1") loHTTP.Open("POST", "http://myip:8080/upload/", .F.) loHTTP.SetRequestHeader("content-type", "text/plain") && or other mime types for other file types.
    loHTTP.SetRequestHeader("content-disposition", 'attachment; filename="Movies.txt"')
    loHTTP.Send(filecontent)

    Bye, Olaf.

    With content-type application/x-www-form-urlencoded you indicate you send form data, which would need some more sections in the body you finally send. As you just send a file the content-type has to be the files html mime type.

    If you want to stay with application/x-www-form-urlencoded, ie the HFS server expects a form submit, you have to go the route using fiddler to see how it's done, or you can read through several RFC documents.


    Olaf Doschke - TMN Systemberatung GmbH

    http://www.tmn-systemberatung.de



    Sunday, April 24, 2016 2:15 PM