- David Hepburn
- PowerBuilder
- Monday, 2 August 2021 11:46 AM UTC
I need to post some text data from my PB2019 app to my PHP script running on a Windows IIS server. I think I need to use HTTPclient's PostData function to do this (yes/no?) There are plenty of examples how to use the PostData function but nothing seems to show how to receive the data.
In examples I've found, they seem to suggest to do something like this:
li_fileno = FileOpen('C:\test\test.txt',TextMode!)
FileReadEx(li_fileno,ls_TotalStrData)
FileClose(li_fileno)
lnv_HttpClient = Create HttpClient
lnv_HttpClient.SetRequestHeader("Content-Length", String(Len(ls_TotalStrData)*2)
if lnv_HttpClient.PostDataStart("https://www.xyz.com/testing/uploadfiletest2.php") = 1 then
li_PackCount = Round(Len(ls_TotalStrData) / 1024,0) * 2
for i = 1 to li_PackCount
//send data in 1024 byte chunks
ls_NextData = mid(ls_TotalStrData, (i - 1) * 1024 + 1, 1024)
li_rc = lnv_HttpClient.PostData(ls_NextData, Len(ls_NextData)* 2)
if li_rc <> 1 then exit
next
li_rc = lnv_HttpClient.PostDataEnd()
end if
What this doesn't show me is how to receive this data is my PHP script. A name hasn't been given to this data to be received using PHP's $_POST['fieldname']
Here's my uploadfiletest2.php script:
$fh = fopen('1.txt', 'w');
fwrite($fh,'Start');
foreach ($_POST as $name => $val) {
$data .= htmlspecialchars($name . ': ' . $val);
fwrite($fh,$data);
}
fwrite($fh,'End');
fclose($fh);
This is what I get in my local "1.txt" file on my server:-
StartEnd
There doesn't seem to be any post data received in my PHP script. What am I doing wrong? Am I even using PostData correctly to send text to a PHP script?
Find Questions by Tag
Helpful?
If a reply or comment is helpful for you, please don’t hesitate to click the Helpful button. This action is further confirmation of their invaluable contribution to the Appeon Community.