Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Msxmlhttp sending image data
Message
From
25/07/2014 10:15:40
Mike Yearwood
Toronto, Ontario, Canada
 
General information
Forum:
Visual FoxPro
Category:
ActiveX controls in VFP
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01603736
Message ID:
01604653
Views:
105
Hey Rick

Can you translate this PHP curl code to vfp? I tried with libcurl, but I am not getting any success.

$ch = curl_init("https://api.realsatisfied.com/v1/image.json");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_USERPWD, "userid:password");
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_POST, true);
$payload = array(
"file_path"=>"@/env/david/workspace/realestatesat/public/images/td_agent_photo.jpg",
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$json_return = curl_exec($ch);
echo $json_return;
exit();



>If the data in the body is *just* raw binary data then the photo is not being sent by multipart-form. Multipart form includes mime headers for the data followed by the content and then separated by Mime boundaries.
>
>if they're sending raw data it's just a raw HTTP request with raw image content type (ie. Content-Type: image/jpeg).
>
>Just not sure how you can actually get the binary data into XmlHttp's send buffer. A COM string assignment in Send() will truncate at nulls (0 which might be present in binary data and images)...
>
>Verified though that binary results can now be read directly by VFP as they come back as VARTYPE() Q. Prior to the varbinary type this wasn't possible and you had to resort to ADO Streams to read the ResponseStream rather than ResponseBody.
>
>Either way - using XmlHttp is fraught with issues once you go beyond the basics - it's just very inconsistent in how data is accepted and read, not to mention the funky mostly undocumented attribute based customizations for extended functionality like authentication.
>
>+++ Rick ---
>
>>Hey Rick
>>
>>Thanks for contributing to this! I used fiddler2 to get the raw payload from the provider's own API testbed. I can see exactly what his end is expecting. Interestingly enough, the filetostr() vfp function of a jpg looks to me like the stuff in his payload.
>>
>>>Argh - save yourself the pain of using XmlHttp for anything but basic HTTP requests... seriously. So many issues with that and file uploads require separate Stream objects out of the ADO library.
>>>
>>>with wwHttp:
>>>
>>>
>>>Do wwHTTP
>>>
>>>loHttp = CREATEOBJECT("wwHTTP")
>>>loHttp.nHttpPostMode = 2  && multipart forms
>>>loHttp.AddPostKey("image","c:\temp\sailbig.jpg",.T.)
>>>loHttp.AddPostKey("notes","cool shot from the other day")
>>>
>>>lcResult = loHttp.HttpGet("http://somesite.com/uploadimages/")
>>>IF (loHttp.nError != 0)
>>>   ? loHttp.cErrorMsg
>>>   RETURN
>>>ENDIF
>>>
>>>? lcResult
>>>
>>>
>>>more info here:
>>>http://www.west-wind.com/webconnection/wwClient_docs/_0rs0twgr6.htm
>>>
>>>+++ Rick ---
>>>
>>>>Hi all
>>>>
>>>>I'm using msxmlhttp v 6.0 to get/post simple things. Now I've been asked to send an image. The enctype must be "multipart/form-data".
>>>>
>>>>o=CREATEOBJECT("Empty")
>>>>ADDPROPERTY(m.o,"FirstName","Mike")
>>>>ADDPROPERTY(m.o,"LastName","Yearwood")
>>>>oJSON=CREATEOBJECT("Json")
>>>>lcJSON = oJSON.Stringify(m.o)
>>>>?m.lcJSON
>>>>
>>>>oHTTP = CREATEOBJECT("MSXML2.XMLHTTP.6.0")
>>>>cusername="cantsay"
>>>>cpassword="wontsay"
>>>>cUrl="https://somewhere.com/overtherainbow"
>>>>luResult = oHTTP.OPEN("GET", m.cURL, .F., m.cUserName, m.cPassword)
>>>>lcEncode64=STRCONV(m.cUserName+":"+m.cPassword,13)
>>>>oHTTP.SetRequestHeader("Authorization", "Basic "+m.lcEncode64)
>>>>oHTTP.SetRequestHeader("Content-Type", "application/json")
>>>>
>>>>oHTTP.SEND()
>>>>
>>>>?oHTTP.Status()
>>>>
>>>>Where and how would I go about adding a filename and a data stream?
>>>>
>>>>Thanks
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform