1. Chen Mey Lee
  2. PowerBuilder
  3. Monday, 19 April 2021 01:59 AM UTC

Hi,

I tried to get Response hander from web page but it return empty value when the header value get from Form.Data.  It worked when hardcode the value (refer to below dbweb.aspx ) :-

PB logic:-

int li_rc, li_status
string ls_header, ls_body,ls_ContentType
HttpClient lnv_HttpClient


lnv_HttpClient = Create HttpClient
lnv_HttpClient.SetRequestHeader("Content-Type", "text/html; charset=utf-8")
li_rc = lnv_HttpClient.SendRequest("POST", "http://10.204.185.43/APT/dbweb.aspx")
li_status = lnv_HttpClient.GetResponseStatusCode()
if li_rc = 1 and ( li_status = 200 OR li_status = 302) then
   ls_header= lnv_HttpClient.GetResponseHeader("dbwebparms")
    messagebox("ls_header", ls_header)
end if 

-----------------------------------------

default.aspx  :

<html>
<head>
<title>APT</title>
</head>
<body>
<form id="apt" runat="server" action="dbweb.aspx" method="post">
<label for="UID">Login ID:</label>
<input type="text" id="UID" name="UID"><br><br>
<label for="PWD">Password:</label>
<input type="password" id="PWD" name="PWD"><br><br>
<input type="submit" value="Submit">
<input type="hidden" id="COMP" name="COMP" value="031">
<input type="hidden" id="PLAN" name="PLAN" value="32">
<input type="hidden" id="SSN" name="SSN" value=>
<input type="hidden" id="ENV" name="ENV" value="DEVELOP">
<input type="hidden" id="APP" name="APP" value="SB">
<input type="hidden" id="EXE" name="EXE" value="pension.exe">
</form>
</body>
</html>

----------------------------------------------------------------------------

dbweb.aspx :

<script>
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

void Page_Load(object sender, EventArgs e)
{

if (Response.IsClientConnected)
{
int loop1;
NameValueCollection coll;

string ls_name;
string ls_value;

//Load Form variables into NameValueCollection variable.
coll=Request.Form;
// Get names of all forms into a string array.
String[] arr1 = coll.AllKeys;
StringBuilder sb = new StringBuilder();
for (loop1 = 0; loop1 < arr1.Length; loop1++)
{
ls_name = null;
ls_value = null;
ls_name = arr1[loop1];
ls_value = coll[arr1[loop1]];
if (ls_name == "COMP" || ls_name == "PLAN" || ls_name == "SSN" || ls_name == "ENV"
|| ls_name == "APP" || ls_name == "EXE" || ls_name == "APP" || ls_name == "UID" || ls_name == "PWD"
&& ls_value != null)
{sb.Append(string.Format("/{0}={1} ", ls_name, ls_value));}
}
string ls_parms;
ls_parms = null;
ls_parms = sb.ToString();
//Response.Write(ls_parms);
Response.Headers.Add("dbwebparms",ls_parms);
//Response.Headers.Add("dbwebparms", "/UID=adca8li /PWD=123 /COMP=031 /PLAN=32 /SSN= /ENV=DEVELOP /APP=SB /EXE=pension.exe");
Response.Redirect("http://10.204.185.43/APT/dbweb/",true);

}
else
{Response.End();}
}
</script>

-------

Daryl Foster Accepted Answer Pending Moderation
  1. Monday, 19 April 2021 09:41 AM UTC
  2. PowerBuilder
  3. # 1

Hi Chen,

 

Can you see if you can run this code from Powerbuilder and show us what the MessageBox displays?  It will help us see what is happening with the http request.

 

int li_rc
string ls_body
HttpClient lnv_HttpClient

ls_body = 'UID=userid'
ls_body += '&PWD=password'
ls_body += '&ENV=DEVELOP'

lnv_HttpClient = Create HttpClient
lnv_HttpClient.SetRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
li_rc = lnv_HttpClient.SendRequest("POST", "http://10.204.185.43/APT/dbweb.aspx", ls_body)

if li_rc = 1 then
    string ls_responsestatuscode, ls_responsestatustext, ls_all_headers

    ls_responsestatuscode = string(lnv_HttpClient.GetResponseStatusCode())
    ls_responsestatustext = lnv_HttpClient.GetResponseStatusText()
    ls_all_headers = lnv_HttpClient.GetResponseHeaders()
    
    MessageBox('Debug', 'Response Status Code = ' + ls_responsestatuscode &
        + '~r~nResponse Status Text = ' + ls_responsestatustext &
        + '~r~nHeaders = ~r~n' + ls_all_headers)
else
    MessageBox('Debug', 'Something went wrong.~r~nReturn Code = ' + string(li_rc))
end if

destroy lnv_HttpClient

Comment
  1. Chen Mey Lee
  2. Monday, 19 April 2021 10:18 AM UTC
I have attached the debug message , the dbwebparm header is getting from the body value. But we need to get UID and PWD from form data web page after user enter user id and password.

  1. Helpful
  1. Daryl Foster
  2. Monday, 19 April 2021 10:48 AM UTC
Hi Chen, I can't see where you have attached the debug message?



I'm still a bit confused about how you are trying to use Powerbuilder for your application. Do you want to display default.aspx and use that to submit your form? If that is the case you probably need to use the WebBrowser control and not the HttpClient control.



If you want to emulate the default.aspx page from Powerbuilder, you can create a Powerbuilder entry window where the user can enter the username and password and then you would use the HttpClient code similar to what I have posted above to submit the form data to the server and then handle the response.



I can see that you've got default.aspx and dbweb.aspx as part of your application, but how does Powerbuilder fit into what you are trying to achieve?
  1. Helpful
There are no comments made yet.
Daryl Foster Accepted Answer Pending Moderation
  1. Monday, 19 April 2021 07:23 AM UTC
  2. PowerBuilder
  3. # 2

Hi Chen,

 

Can you tell us exactly what you are trying to achieve? What is the purpose of the re-direct to
http://10.204.185.43/APT/dbweb/? in dbweb.aspx

I think the redirect should return a 302 back to your lnv_HttpClient in Powerbuilder and a Location header. Then your Powerbuilder code would need to read the Location header and make another SendRequest to that URL passing whatever data that url is expecting. (All of that is done automatically in a normal web browser)

Can you share your updated Powerbuilder code that submits the form?

Also can you get all the headers returned from the response so we can see exactly what is returned from the http request:

string ls_all_headers

ls_all_headers= lnv_HttpClient.GetResponseHeaders()
MessageBox("ls_all_headers", ls_all_headers)

 

 

Comment
  1. Chen Mey Lee
  2. Monday, 19 April 2021 07:39 AM UTC
Tje dbweb.aspx get all form data and add it to response,header -> dbwebparms: /UID=adca8li /PWD=123 /COMP=031 /PLAN=32 /SSN=911110001 /ENV=DEVELOP /APP=SB /EXE=pension.exe and then redirect to cloud app ->Response.Redirect("http://10.204.185.43/APT/dbweb/";,true)



The PB cloud app logic below will read the header as input argument ->



int li_rc, li_status

string ls_header, ls_body,ls_ContentType

HttpClient lnv_HttpClient





lnv_HttpClient = Create HttpClient

lnv_HttpClient.SetRequestHeader("Content-Type", "text/html; charset=utf-8")

li_rc = lnv_HttpClient.SendRequest("POST", "http://10.204.185.43/APT/dbweb.aspx";)

li_status = lnv_HttpClient.GetResponseStatusCode()

if li_rc = 1 and ( li_status = 200 OR li_status = 302) then

ls_header= lnv_HttpClient.GetResponseHeader("dbwebparms")

messagebox("ls_header", ls_header)

end if
  1. Helpful
  1. Daryl Foster
  2. Monday, 19 April 2021 07:46 AM UTC
That Powerbuilder code looks the same as your original post. You haven’t updated it to add the form data like in the original link I provided. dbweb.aspx is expecting form data which you aren’t sending from Powerbuilder.
  1. Helpful
There are no comments made yet.
Chen Mey Lee Accepted Answer Pending Moderation
  1. Monday, 19 April 2021 06:00 AM UTC
  2. PowerBuilder
  3. # 3

Tried, issue persist.

Found below solution , can PB get session or cookie value ?

https://www.codeproject.com/Questions/1347449/How-do-I-add-get-response-header-value-in-the-page

You'll probably need to store your data in the Session or a cookie instead. A redirect simply adds additional headers to your response that tells the browser to request the page being redirected to. As this is the request that triggers pageb, all of the headers you sent from pagea are lost.

Comment
There are no comments made yet.
Daryl Foster Accepted Answer Pending Moderation
  1. Monday, 19 April 2021 03:55 AM UTC
  2. PowerBuilder
  3. # 4

Hi Chen, your Powerbuilder code isn't sending any form data with the POST request, so ls_parms in dbweb.aspx will be setting the dbwebparms response header to empty string.  If you want your Powerbuilder code to emulate the default.aspx page you'll need to code the form data in the body to send.  Here is a similar question from someone the other day:

https://community.appeon.com/index.php/webinars/elevate-discussion/posting-forms-with-httpclient

 

Comment
  1. Chen Mey Lee
  2. Monday, 19 April 2021 06:02 AM UTC
0

Votes

Tried, issue persist.



Found below solution , can PB get session or cookie value ?



https://www.codeproject.com/Questions/1347449/How-do-I-add-get-response-header-value-in-the-page



You'll probably need to store your data in the Session or a cookie instead. A redirect simply adds additional headers to your response that tells the browser to request the page being redirected to. As this is the request that triggers pageb, all of the headers you sent from pagea are lost.
  1. Helpful
There are no comments made yet.
Chen Mey Lee Accepted Answer Pending Moderation
  1. Monday, 19 April 2021 02:10 AM UTC
  2. PowerBuilder
  3. # 5

Hi ,

Attached is Form Data  value capture in default.aspx.

Attachments (1)
Comment
There are no comments made yet.
Chen Mey Lee Accepted Answer Pending Moderation
  1. Monday, 19 April 2021 02:07 AM UTC
  2. PowerBuilder
  3. # 6

Hi,

 

Attached is the response header added to dbweb.aspx. 

Attachments (1)
Comment
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.