Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / September 2005

Tip: Looking for answers? Try searching our database.

Help with HttpWebRequest.Method

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Roger - 07 Sep 2005 02:39 GMT
Thanks in advance for any help offered.

I am trying to fill out a form on a web page and submit the form data to the
web server , all from within my vb program.

The html sorce ( reduced for this post is)

<FORM ACTION="a_valid_url.cfm" METHOD="POST">
<BR>
    <P>Trend
        <SELECT NAME="trend_id">
            <OPTION VALUE="ALL;ALL">ALL
            <OPTION VALUE="FIRST;abc">First
            <OPTION VALUE="SECOND;abc">Second
        </SELECT>
    <P>
    <TABLE WIDTH=400>
    <TR ALIGN=CENTER><TD>Month
        <SELECT NAME="month">
                                       <OPTION VALUE="ALL" SELECTED>ALL
                                       <OPTION VALUE="1">Jan
                                       <OPTION VALUE="2">Feb
                                 </SELECT>
                                 </TD>
<TD>Day
          <SELECT NAME="DAY">
            <OPTION VALUE="ALL">ALL
            <OPTION VALUE="1">1
            <OPTION VALUE="2">2       
            </SELECT>
</TD>
    </TR>
</TABLE>
    <P><INPUT TYPE="submit" VALUE="Search">
</FORM>

In my vb program I set up a HttpWebRequest as follows.
I have no experience with HTML or Jscript. Limited experience with VB.

I want to submit a trend_id of "FIRST" with "ALL" months and "ALL" days from
my vb prog.

       Dim STE As String = "http://www.another_valid_url"

       Dim m_cred As New NetworkCredential("username", "password")
       Dim m_Cache As New CredentialCache()

       m_Cache.Add(New Uri(STE), "Basic", m_cred)
       m_Cache.Add(New Uri(STE), "Digest", m_cred)
       m_Cache.Add(New Uri(STE), "NTLM", m_cred)
       m_Cache.Add(New Uri(STE), "Kerberos", m_cred)

       Dim mm_req As HttpWebRequest = CType(WebRequest.Create(STE),
HttpWebRequest)

       mm_req.Credentials = m_Cache

       Dim srch As String

       srch = "I'm not sure what goes here??"
       Dim qq() As Byte = Encoding.ASCII.GetBytes(srch)
       mm_req.Method = "POST"
       mm_req.ContentLength = qq.Length
       mm_req.Timeout = 60000

       Dim req_stream As Stream = mm_req.GetRequestStream
       req_stream.Write(qq, 0, qq.Length)
       req_stream.Close()

       Dim mm_resp As HttpWebResponse = CType(mm_req.GetResponse(),
HttpWebResponse)

       Dim readStream As New StreamReader(mm_resp.GetResponseStream,
Encoding.ASCII)
       Dim ch As String = readStream.ReadToEnd
       ...
       ...
       readStream.Close()
       mm_resp.Close()

I have tried various ways of constructing 'srch' but I keep getting back the
unfilled form. The server doesnt proceed to the url in the Action field of
the form. The username & password are correct.

Thanks anyone
Signature

Roger

 Was this post helpful to you?  


--
Roger

Cowboy (Gregory A. Beamer) - MVP - 07 Sep 2005 13:40 GMT
My first question is why are you circumventing the normal operation of
ASP.NET and creating a handler in this manner? I am not criticizing the use
of a handler, if necessary, but I find very few cases where this is necessary.

In this instance, it appears you desire the following:

1. Submit form
2. Handler grabs request and processes the form collection
3. Handler passes off to a cfm page for response

While this appears as simple as creating a post event handlerin CodeBehind,
it is much more complex. There are many moving parts. As part of the system
is out of your control (in the IDE), it is also difficult to debug.
Compounding this is your admitted lack of skill in VB, HTML, etc.

In ASP.NET, you have built in infrastructure to handle form submit. There
are times you have to step outside of that box, but you should be careful
about doing it. Make sure there is a really good reason to build your own
before building.

The first step outside of the box would be a submission to the ColdFusion
page and let it handle things, if your core competency is ColdFusion. It is
not ideal, but it can work.

Overall, when I circumvent the normal page submit, my focus is on setting up
an HttpHandler or HttpModule and installing it on the machine. This, in and
of itself, is a bit harder to debug. I will make sure the handler/module does
not contain a lot of page specific code. This is necessary for my sanity.

If you need to handle page requests dynamically, you can look at a
model-view-controller pattern, but this still does not solve the "passing off
to ColdFusion" part of the problem.

In short: Is it really necessary to pass off to ColdFusion? If yes, is it
absolutely necessary to handle the request before passing it off? Think
through these two questions very carefully, as the entire architecture of
your app is at stake.

Signature

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************

> Thanks in advance for any help offered.
>
[quoted text clipped - 81 lines]
>
> Thanks anyone
Joerg Jooss - 12 Sep 2005 22:06 GMT
> Thanks in advance for any help offered.
>
[quoted text clipped - 47 lines]
>         m_Cache.Add(New Uri(STE), "NTLM", m_cred)
>         m_Cache.Add(New Uri(STE), "Kerberos", m_cred)

Setting four different authentication schemes isn't necessary. Use the
one that is really being used ;-)


>         Dim mm_req As HttpWebRequest = CType(WebRequest.Create(STE),
> HttpWebRequest)
[quoted text clipped - 4 lines]
>
>         srch = "I'm not sure what goes here??"

You have to create a proper HTLM form query string, i.e.
fieldName1=fieldValue1&fieldName2=fieldValue2&...&fieldName<n>=fieldValu
e<n>

See http://www.w3.org/TR/html4/interact/forms.html#h-17.13.3 for
details.

So what you need is string like
"trend_id=1&month=all&DAY=all"

Cheers,
Signature

http://www.joergjooss.de
mailto:news-reply@joergjooss.de


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.