Jump to content
Sign in to follow this  

Utilizar o WinHttpRequest para upload em VFP

Recommended Posts


Boas pessoal.

Eu estou a tentar  usar o WinHttpRequest para fazer upload mas não estou a conseguir.

O código que utilizo no VFP é:

filecontent = FileToStr(ficheiro)

loHTTP = CREATEOBJECT("WinHttp.WinHttpRequest.5.1")    
loHTTP.Open("POST", "http://www.-------.com/webspace/upload.php", .F.)
loHTTP.SetRequestHeader("content-type", "text/plain")
loHTTP.setRequestHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)")

varrequest	= 'attachment; filename="' + JUSTFNAME(ficheiro) + '"'

loHTTP.SetRequestHeader("content-disposition", varrequest)

WAIT WINDOW TRANSFORM(loHTTP.status) + " - " + loHTTP.responseText + " - " + loHTTP.ResponseBody


O Codigo em PHP é:

    $uploaddir = 'upload/';
    $uploadfile = $uploaddir . $_FILES['file']['name'];

    if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {
        echo "File successfully uploaded.\n";


o log do PHP esta a dar estes erros

[12-Dec-2018 12:28:02 UTC] PHP Notice:  Undefined index: file in /home/webspace/upload.php on line 3
[12-Dec-2018 12:28:02 UTC] PHP Notice:  Undefined index: file in /home/webspace/upload.php on line 5

Alguém pode ajudar?


* Dupliquei o tópico porque não sei onde seria o mais indicado para fazer a questão.


Share this post

Link to post
Share on other sites

Mudei o codigo mas agora quando faço var_dump o ficheiro aparece como HTTP_RAW_POST_DATA

Código actual:

    loHTTP = CREATEOBJECT("WinHttp.WinHttpRequest.5.1")    
    loHTTP.Open("POST", "http://www.----------.com/webspace/getfile.php", .F.)
    xBOUNDARY   = "+++++"
    vbCrLf      = CHR(10) + CHR(13)

    filecontent = "--" + xBOUNDARY + vbCrLf
    filecontent = filecontent + 'Content-Disposition: form-data; name="file"; filename="' + JUSTFNAME(ficheiro) + '"' + vbCrLf
    filecontent = filecontent + "Content-type: text/plain" + vbCrLf + vbCrLf
    filecontent = filecontent + FileToStr(ficheiro)
    filecontent = filecontent + vbCrLf
    filecontent = filecontent + "--" + xBOUNDARY + "--"
    filecontent = filecontent + vbCrLf

    loHTTP.SetRequestHeader("CONTENT_TYPE", "multipart/form-data; boundary=" + xBOUNDARY + vbCrLf)
    loHTTP.SetRequestHeader("CONTENT_NAME", JUSTFNAME(ficheiro) + vbCrLf)


var_dump no PHP


array(7) {
  string(245) "--+++++

Content-Dis-data; name="file"; filename="Oo2Teste.txt"

Content-type: text/plain

00000000000000|00000000000000| BASE|00|GERAL|00|00
1.1|1.1|Leiria - PD Azambuja - CMR1|00|GERAL|00|00


  array(0) {
  array(0) {
  array(0) {
  array(0) {
  array(38) {
    string(28) "/usr/local/bin:/usr/bin:/bin"
    string(4) "/tmp"
    string(4) "/tmp"
    string(4) "/tmp"
    string(1) "/"
    string(3) "*/*"
    string(10) "Keep-Alive"
    string(25) "text/plain; Charset=UTF-8"
    string(5) "20341"
    string(57) "Mozilla/4.0 (compatible; Win32; WinHttp.WinHttpRequest.5)"
    string(35) "multipart/form-data; boundary=+++++"
    string(14) "Oo2Teste.txt"
    string(1) "1"
    string(0) ""
    string(6) "Apache"
    string(8) "HTTP/1.1"
    string(4) "POST"
    string(0) ""


Edited by cjulio

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.