Solved

How to use Webbrowser and POST

Posted on 2002-04-27
23
149 Views
Last Modified: 2010-05-02
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
Comment
Question by:Leandro
  • 11
  • 8
  • 4
23 Comments
 
LVL 12

Expert Comment

by:roverm
Comment Utility
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
 
LVL 12

Expert Comment

by:roverm
Comment Utility
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
 

Author Comment

by:Leandro
Comment Utility
 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
 
LVL 12

Expert Comment

by:roverm
Comment Utility
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
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
hearing... how to it ends?
0
 
LVL 12

Expert Comment

by:roverm
Comment Utility
Hi Richie, what do you mean ? "how to it ends" Mark
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
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
 
LVL 12

Expert Comment

by:roverm
Comment Utility
Richie:ROTFLMAOPIMP!
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
:O
0
 

Author Comment

by:Leandro
Comment Utility
 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
 
LVL 12

Expert Comment

by:roverm
Comment Utility
But the INet control "reports" progress too! In the StateChanged event you've got 12 steps. Can't you use that ?
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:Leandro
Comment Utility
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
 
LVL 12

Expert Comment

by:roverm
Comment Utility
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
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
server stores the page in somewhere before send it to you?
0
 

Author Comment

by:Leandro
Comment Utility
 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
 
LVL 12

Expert Comment

by:roverm
Comment Utility
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
 

Author Comment

by:Leandro
Comment Utility
Thank you very mucth, it was really a mistake, but the problem is still ocurring. The variables return NULL.
0
 
LVL 12

Accepted Solution

by:
roverm earned 150 total points
Comment Utility
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
 

Author Comment

by:Leandro
Comment Utility
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
 

Author Comment

by:Leandro
Comment Utility
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
 
LVL 12

Expert Comment

by:roverm
Comment Utility
k, glad your problem is solved!

Thanks for the points.

D'Mzzl!
RoverM
0
 
LVL 12

Expert Comment

by:roverm
Comment Utility
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
 

Author Comment

by:Leandro
Comment Utility
You're welcome, thanks for the help...
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now