Send request to AVFP from VFP application

Topics: User Forum
Jun 21, 2016 at 4:29 PM
Hi all!

I'm trying to send a HTTP Request to AVFP page but i can't retrive the data that i send.

I use this code in my VFP application:
        oHTTP.Open("GET", "http://localhost/att/test2.avfp", .F.)
        oHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
        param = [?p1=] + [aa]
        param = param + [&p2=] + [bb]
        ? oHTTP.responseText
In my AVFP page, instead, i have this code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="it">
    LOCAL fa, fb
    STORE '' TO fa, fb
    fa      =   oRequest.QueryString("p1")
    fb      =   oRequest.QueryString("p2")
Hovewear, the variables "fa" and "fb" are empty and yours vartype returns "X". The same method, in PHP works fine. Where is the problem with AVFP? The wrong setRequestHeader ?

Thanks and have a nice day
Jun 22, 2016 at 4:25 PM
I've included all parameters into the principal link with this code:
oHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
param = [?p1=] + [aa]
param = param + [&p2=] + [bb]
oHTTP.Open("GET", "http://localhost/att/test2.avfp"+param, .F.)
For now this is a good way to solve the problem. At the end, i need to pass only two parameters.

You can close the topic.
Marked as answer by mr_ocean on 6/22/2016 at 8:25 AM
Nov 3, 2016 at 5:03 PM
To send form-encoded data as request's data, you must use POST instead of GET. Then, at AVFP, you use oRequest.Form("name") to retrieve posted values. Or, if you are using the extended version, then you can use AVPOST() function.