I am using progress 10.1b on my PC, running windows XP.
I am following the code example in P125506 to post a HTTP Request. The code sample is at bottom of message.
I basically connect to my localhost on my port, and I post to the URL on my network.
Do I need some sort of server running to facilitate all this communication?
The response I get when I post is NOT from the URL I thought I was posting to.
DEFINE VARIABLE vcHost AS CHARACTER INITIAL "localhost"
NO-UNDO.
DEFINE VARIABLE vcPort AS CHARACTER INITIAL "8080"
NO-UNDO.
DEFINE VARIABLE vhSocket AS HANDLE
NO-UNDO.
CREATE SOCKET vhSocket.
vhSocket:CONNECT('-H ' + vcHost + ' -S ' + vcPort) NO-ERROR.
IF vhSocket:CONNECTED() = FALSE THEN
DO:
MESSAGE "Connection failure" VIEW-AS ALERT-BOX.
MESSAGE ERROR-STATUS:GET-MESSAGE(1) VIEW-AS ALERT-BOX.
RETURN.
END.
ELSE
MESSAGE "Connect" VIEW-AS ALERT-BOX.
vhSocket:SET-READ-RESPONSE-PROCEDURE('getResponse').
/* supposes there is an webspeed app called yourapp.w that receives
param1, param2, param3 */
RUN PostRequest (INPUT
'/scripts/cgiip.exe/WService=wsbroker1/yourApp.w',
'param1=value¶m2=value¶m3=value').
WAIT-FOR READ-RESPONSE OF vhSocket.
vhSocket:DISCONNECT() NO-ERROR.
DELETE OBJECT vhSocket.
QUIT.
PROCEDURE getResponse:
DEFINE VARIABLE vcWebResp AS CHARACTER NO-UNDO.
DEFINE VARIABLE lSucess AS LOGICAL NO-UNDO.
DEFINE VARIABLE mResponse AS MEMPTR NO-UNDO.
IF vhSocket:CONNECTED() = FALSE THEN do:
MESSAGE 'Not Connected' VIEW-AS ALERT-BOX.
RETURN.
END.
lSucess = TRUE.
DO WHILE vhSocket:GET-BYTES-AVAILABLE() > 0:
SET-SIZE(mResponse) = vhSocket:GET-BYTES-AVAILABLE() + 1.
SET-BYTE-ORDER(mResponse) = BIG-ENDIAN.
vhSocket:READ(mResponse,1,1,vhSocket:GET-BYTES-AVAILABLE()).
vcWebResp = vcWebResp + GET-STRING(mResponse,1).
END.
/* BR> *
*
*PUT HERE THE CODE TO MANIPULATE THE ANSWER
*/
END.
PROCEDURE PostRequest:
DEFINE VARIABLE vcRequest AS CHARACTER.
DEFINE VARIABLE mRequest AS MEMPTR.
DEFINE INPUT PARAMETER postUrl AS CHAR. /* URL that will send
the data. It must be all the path after the server. IE:
/scripts/cgiip.exe/WService=wsbroker1/myApp.htm */
DEFINE INPUT PARAMETER postData AS CHAR. /* Parameters to be sent
in the format paramName=value¶mName=value¶mName=value */
vcRequest = 'POST ' + postUrl + ' HTTP/1.0rn' +
'Content-Type: text/xmlrn' +
'Content-Length:' + string(LENGTH(postData)) + 'rn' +
'rn' +
postData + 'rn'.
MESSAGE vcREquest VIEW-AS ALERT-BOX.
SET-SIZE(mRequest) = 0.
SET-SIZE(mRequest) = LENGTH(vcRequest) + 1.
SET-BYTE-ORDER(mRequest) = BIG-ENDIAN.
PUT-STRING(mRequest,1) = vcRequest .
vhSocket:WRITE(mRequest, 1, LENGTH(vcRequest)).
END PROCEDURE..
Your example connection parameters are localhost:8080. The port 8080 is normally used for proxy requests for HTTP. Port 80 is normally used for http. If you plan on requesting data using this example you are going to need a web server such as Apache or IIS.
OK,
There were several issues that had to be worked through.
I had to correct my host and port to get my program to work.
Thank you all!!!