Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 172
  • Last Modified:

How to use Webbrowser and POST

I have to send SQl Server login information to an ASP page that returns an HTML report to a Webbrowser control in my application. So I do it from the Webbrowser by POST, using the code below to send it, I can get the number of bytes sent using Request.ServerVariables("CONTENT_LENGTH") but when I try to get the variables using Request.QueryString("usr") or Request.Form("usr") they do not exist, could anyone help me please. Thank you and sorry for my poor english. The code is :

Public Sub OpenReport(sPath As String, sPost As String, sHeader As String)
    'Ex.
    ' sPath = url
    ' sPost = "pwd=passhere&usr=leandro"
    ' sHeader = "Content-Type: application/x-www-form-urlencoded" & vbCrLf
    Dim bPost() As Byte
    ReDim bPost(Len(sPost))
    bPost = StrConv(sPost, vbFromUnicode)
    '
    Web.Navigate sPath, 14, vbEmpty, bPost, sHeader
    '...
End Sub
0
Leandro
Asked:
Leandro
  • 11
  • 8
  • 4
1 Solution
 
rovermCommented:
Why don't you use the INet control (Microsoft Internet Controls - shdocvw.oca) ?

Then the code would be:

oInetControl.Execute "www.experts-exchange.com/jsp/memberLogin.jsp", "POST", "loginMemberName=" & sMemberID & _
                "&loginPassword=" & sPassword, _
                "Content-Type: application/x-www-form-urlencoded"

Where sMemberID is the member to login and sPassword is the password.

D'Mzzl!
RoverM
0
 
rovermCommented:
btw:You can use the oInetControl_StateChanged event to monitor the progress since there is nothing visible when you use the INet control.
But it's way faster than the webbrowser! ;-)

D'Mzzl!
RoverM
0
 
LeandroAuthor Commented:
 Ok, but the problem is that I never used Inet Control and I noticed that it does not have a graphical interface to show the report to the user. Would I have to save a temporary document and then open it in the WebBrowser, or there is another way to do it ?

  Anyway, thank you.
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
rovermCommented:
Nope, first save it, then show it in the webbrowser control.
But that still would be faster.

The INet control is very well documented in the MSDN Library, but if you don't have it I could build you an example. Just say so then.

D'Mzzl!
RoverM
0
 
Richie_SimonettiIT OperationsCommented:
hearing... how to it ends?
0
 
rovermCommented:
Hi Richie, what do you mean ? "how to it ends" Mark
0
 
Richie_SimonettiIT OperationsCommented:
I would like to know how it will ends...
I am a gentleman, you know, so i will wait until you post an answer, if you would be stooped, i could try by myself...
;)
Cheers to both!
0
 
rovermCommented:
Richie:ROTFLMAOPIMP!
0
 
Richie_SimonettiIT OperationsCommented:
:O
0
 
LeandroAuthor Commented:
 The only problem with this solution is that, in some cases my app calls long running queries and I'm gonna show some response to the user. Like a progressbar or returning the document with Response.Flush.
  This calls are very mutable, so I can't preview how mutch time It will take to execute them, this eliminates the posibility of making a fake progressbar.
  So, I think that although the INet can call the page, it will be not a good solution for this specific kind of report.
  Thanks for the comments.
0
 
rovermCommented:
But the INet control "reports" progress too! In the StateChanged event you've got 12 steps. Can't you use that ?
0
 
LeandroAuthor Commented:
Yes, I know that, but this progress won't consider the real progress based on the Loop that generates the table, if the table has, for example 300 lines, the INet control has no way to know it, so it can't report the real progress, neighter I could know how many lines It will return, that's why I said that I can't fake the progressbar, it's very impredictable.
0
 
rovermCommented:
That's true, but a *real* website doesn't "know" that either. The generation of that table will be done at the server. The page doesn't send a "how big am I" signal to the browser as well.

Can't you deliver the nessacary data not via another way ?
0
 
Richie_SimonettiIT OperationsCommented:
server stores the page in somewhere before send it to you?
0
 
LeandroAuthor Commented:
 No Richie, the page is not stored anywhere, and roverm, I am not making a website, it's an application with html data reports, but also a website can show the progress with a progress bar control I've got, or I can fire Response.Flush eatch 10 or 20 lines.
  To report is made by sending the Query, the login information and other parameters to an asp page that executes the query (not pre-defined) into SQL Server, and returns a table (with no pre-defined columns, nor size), then I get the returned table properties and fill the html table, this table can have 1, 10, 100 or 500 lines depending on the requested report.
  Thanks again.
0
 
rovermCommented:
Just occured to me in your original coding:
The parameters aren't passed correctly.

Maybe just a typo here ?

You wrote:
sPost = "pwd=passhere&usr=leandro"

While it should be:
sPost = "?pwd=passhere&usr=leandro"

See the questionmark as the first character ?

D'Mzzl!
RoverM
0
 
LeandroAuthor Commented:
Thank you very mucth, it was really a mistake, but the problem is still ocurring. The variables return NULL.
0
 
rovermCommented:
If you build a simple HTML or ASP page, which submits the data to that page, will the variables then show up ?

Like:

<html>
<body>
<form action=myaction.asp method=post>
<input type=text id=usr value="USERNAME">
<input type=text id=password value="PASSWORD">
<input type=submit id=bt_submit value="Submit"
</form>
</body>
</html>

D'Mzzl!
RoverM
0
 
LeandroAuthor Commented:
No the variables didn't show up, the problem was that the Request.Form("zzz") does not return a string, so it's necessary to type (Request.Form("zzz")) to convert since there is no implicit conversion.
And about putting a "?" at the start of the POST string, it does not work, the string must be "pwd=xxx&usr=yyy".
Anyway, thank you, although you didn't give me the explicit answer, your comments helped me in finding the answers. So, I will accept your comments as answer, thank you.
0
 
LeandroAuthor Commented:
No the variables didn't show up, the problem was that the Request.Form("zzz") does not return a string,
so it's necessary to type (Request.Form("zzz")) to convert since there is no implicit conversion.
And about putting a "?" at the start of the POST string, it does not work, the string must be "pwd=xxx&usr=yyy".
Anyway, thank you, although you didn't give me the explicit answer, your comments helped me in finding
the answers. So, I will accept your comments as answer, thank you.
0
 
rovermCommented:
k, glad your problem is solved!

Thanks for the points.

D'Mzzl!
RoverM
0
 
rovermCommented:
btw: You are correct, the questionmark is only nessacary if you type the url in the addressbar or do a window.navigate from script.
0
 
LeandroAuthor Commented:
You're welcome, thanks for the help...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 11
  • 8
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now