1. David Hepburn
  2. PowerBuilder
  3. 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? 

Accepted Answer
René Ullrich Accepted Answer Pending Moderation
  1. Monday, 2 August 2021 12:54 PM UTC
  2. PowerBuilder
  3. # Permalink
Comment
There are no comments made yet.
David Hepburn Accepted Answer Pending Moderation
  1. Monday, 2 August 2021 19:57 PM UTC
  2. PowerBuilder
  3. # 1

Perfect! Thank You.

If you will persist with another question from me - if I'm using PostData to a https website, is the data actually encrypted via the secure protocol or is it just plain text that hackers could intercept easily?

Comment
  1. René Ullrich
  2. Tuesday, 3 August 2021 05:25 AM UTC
Body data is encrypted with HTTPS. But you should use newer secure protocols like TLS 1.2 for better encryption.

To specify it in HttpClient see the SecureProtocol property.

You should also configure your server to not acccept old secure protocols that are not secure enough anymore.

https://en.wikipedia.org/wiki/Transport_Layer_Security
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.