lcData = filetostr("MyFile.dat")
loHTTP = CREATEOBJECT('WinHttp.WinHttpRequest.5.1')
loHTTP.Open("POST", "http://www.MySite.com/MyScript.php", .f.)
loHttp.setrequestheader("content-type",
"application/x-www-form-urlencoded")
IF NOT loHTTP.Send( lcFile )
MESSAGEBOX( loHTTP.ErrorCode+loHTTP.ErrorMsg)
ENDIF
In this script $HTTP_RAW_POST_DATA gets only first 5 symbols
Maybe problem is connected with next info from
loHTTP.GetAllResponseHeaders() :
----------------------------
Date: Mon, 23 Jul 2007 09:24:58 GMT
Server: Apache/1.3.37 (Unix) mod_auth_passthrough/1.8 mod_log_bytes/1.2
mod_bwlimited/1.4 PHP/4.4.4 FrontPage/5.0.2.2635.SR1.2 mod_ssl/2.8.28
OpenSSL/0.9.7e-p1
X-Powered-By: PHP/4.4.4
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html; charset=cp1251
------------------------------
Why Content-Type is not I set with setrequestheader ?
Thanks in advance for any help
The content type is multipart-mixed and the formatting needs to be MIME
encoding blocks for each of the form variables. It's not super trivial to do
but you can look up the format for an upload online. Look up
multipart/form-data; boundary=" + MULTIPART_BOUNDARY + CRLF + CRLF +;
to find out how to format POST data. It looks something like this:
POST /wconnect/wc.dll?wwDemo~FileUpload HTTP/1.1
Referer: http://www.west-wind.com/wconnect/
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1;)
Content-Length: 512
Host: www.west-wind.com
Pragma: no-cache
-----------------------------7d732c36490506
Content-Disposition: form-data; name="File"; filename="C:\Test.htm"
Content-Type: text/html
<html>
<body>
<div style="background-image:url(sailbig.jpg)">
<img src="test.png">
<div>
</body>
</html>
-----------------------------7d732c36490506
Content-Disposition: form-data; name="txtFileNotes"
-----------------------------7d732c36490506
Content-Disposition: form-data; name="btnSubmit"
Upload File
-----------------------------7d732c36490506--
FWIW, you can try wwIPStuff (http://www.west-wind.com/wwClientTools.asp)
with which you can do it a bit easier as it handles the various POST
encodings:
oHTTP = CREATEOBJECT("wwHTTP")
*** Set mode to multi-part form
oHTTP.nHttpPostMode = 2
*** Post a file and a regular form variable
oHttp.AddPostKey("FileVar","d:\temp\wws_invoice.pdf",.T.)
oHttp.AddPostKey("txtFileNotes","test note")
*** Call and get response
lcHTML = oHTTP.HTTPGet("http://localhost/wconnect/FileUpload.wwd")
IF oHTTP.nError # 0
? oHttp.cErrorMsg
ENDIF
*** Go on with life
Hope this helps,
+++ Rick ---
--
Rick Strahl
West Wind Technologies
www.west-wind.com/weblog
"Stoyan Malchev" <stoyan....@pitagor.com> wrote in message
news:eUSazFRz...@TK2MSFTNGP04.phx.gbl...
If you're posting *binary* data with WinHttp you have to resort to encoding
the data into a byte array. The problem is if you pass a VFP string to a COM
function it will terminate at the first CHR(0).
Use:
IF NOT loHTTP.Send( CreateBinary(lcFile) )
to get the data to the server properly formatted as binary.
+++ Rick ---
--
Rick Strahl
West Wind Technologies
www.west-wind.com/weblog
"Stoyan Malchev" <stoyan....@pitagor.com> wrote in message
news:eUSazFRz...@TK2MSFTNGP04.phx.gbl...