CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 23 of 23
  1. #16
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,556

    Re: CHttp... Post with "action"

    The best way to see the content of a valid http POST request is to look at the content of a request from a working program, like your browser.

    Install an http tracer or debugger, which will log all http communications going out of your machine. Then, go to a site that has html for a form on it, click the button on site, and then look at the output from the tracer utility.

    A quick Google search turned up two candidates:

    HttpTracer from Lazy Dog Utilities at http://www.lazydogutilities.com/index.htm

    Fiddler, a HTTP Debugging Proxy at http://www.fiddlertool.com/fiddler/

    As a test, I quickly downloaded and installed HttpTracer, and set my browser (which is IE) to use it as a proxy (I set the proxy to 127.0.0.1 on port 8010, as explained in the Help file). On this page (i.e., the CodeGuru formu) the html includes a form with a "submit reply" and a "preview post" button. When I press the "preview post" button, HttpTracer logs the request as follows:

    Code:
    POST http://www.codeguru.com/forum/newreply.php HTTP/1.0
    Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, application/x-quickviewplus, application/x-shockwave-flash, */*
    Referer: http://www.codeguru.com/forum/newreply.php
    Accept-Language: en-us
    Content-Type: application/x-www-form-urlencoded
    Proxy-Connection: Keep-Alive
    User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)
    Host: www.codeguru.com
    Content-Length: 1320
    Pragma: no-cache
    Cookie: pmt=1; bbuserid=85023; cguserid=MikeAThon; bbpassword=ffffd9b1fffffffffffffffdee88ffff; vbcodemode=1; bbsessionhash=ed4bb4b7f7e55fb47ec1bb75e4f627f0; bbthread_lastview=ax2x-ix339109ysx10x%221115052487%22yix338949ysx10x%221115074342%22y_; RMID=3fcfad0b42717e60
    
    title=Re%3A+CHttp...+Post+with+%22action%22&mode=1&message=The+best+way+to+see+the+content+of+a+valid+http+POST+request+is+to+look+at+the+content+of+a+request+from+a+working+program%2C+like+your+browser.%0D%0A%0D%0AInstall+an+http+tracer+or+debugger%2C+which+will+log+all+http+communications+going+out+of+your+machine.++Then%2C+go+to+a+site+that+has+html+for+a+form+on+it%2C+click+the+button+on+site%2C+and+then+look+at+the+output+from+the+tracer+utility.%0D%0A%0D%0AA+quick+Google+search+turned+up+two+candidates%3A%0D%0A%0D%0AHttpTracer+from+Lazy+Dog+Utilities+at+http%3A%2F%2Fwww.lazydogutilities.com%2Findex.htm%0D%0A%0D%0AFiddler%2C+a+HTTP+Debugging+Proxy+at+http%3A%2F%2Fwww.fiddlertool.com%2Ffiddler%2F%0D%0A%0D%0AAs+a+test%2C+I+quickly+downloaded+and+installed+HttpTracer%2C+and+set+my+browser+%28which+is+IE%29+to+use+it+as+a+proxy+%28I+set+the+proxy+to+127.0.0.1+on+port+8010%2C+as+explained+in+the+Help+file%29.++On+this+page+%28i.e.%2C+the+CodeGuru+formu%29+the+html+includes+a+form+with+a+%22submit+reply%22+and+a+%22preview+post%22+button.++When+I+press+the+%22preview+post%22+button%2C+HttpTracer+logs+the+request+as+follows%3A%0D%0A%0D%0A&iconid=0&s=&do=postreply&t=338949&p=1146221&posthash=dc67ffed7dc20a849ede69da6e45dc59&poststarttime=1115086873&preview=Preview+Post&parseurl=1&emailupdate=1&rating=0
    You can use this output to ensure that your own code matches.

    You can also "see" what your code is sending out since the Wininet functions piggy-back on the proxy that you set into IE (at least I think they do).

    HTH,
    Mike

  2. #17
    Join Date
    Apr 2005
    Posts
    14

    Re: CHttp... Post with "action"

    ok. A few more questions.
    What exactly would my "File type" be? .txt? And do I have to read in the whole file in a huge string to put into "File contents"?


    Thanks.

    P.S. I tried the httptracer and since I'm going directly to a router, not a regular web page, the new settings for IE that I had to put in, made my browser not connect to the router anymore. Thanks for that suggestion though. Made a lot of sense.

  3. #18
    Join Date
    Feb 2003
    Location
    California
    Posts
    334

    Re: CHttp... Post with "action"

    I don't know what the file type would be. What does the file look like?

    If you want, you can post the file and the form it's submitted with. (If the form is any different at all from what you've already posted). I can use it to post against an inspection page here, which would reveal the file type and the exact posted contents, at least.
    Henri Hein
    Principal Engineer, Propel
    Do not credit Propel with my views or opinions.

  4. #19
    Join Date
    Apr 2005
    Posts
    14

    Re: CHttp... Post with "action"

    I've attached the file. It's extension is .dat but it's really a text file.

    Also here is what I got off the router web page.

    Let me know if you need anything else.



    <strong>Router Configuration Upload</strong>
    <table width="100%" border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td>
    <FORM action="/cgi-bin/config" method="POST" enctype="multipart/form-data">

    <p><INPUT TYPE=FILE SIZE=60 NAME="CONFIG" id="browse"></p>
    <p><INPUT type="submit" value="Load" id="submit"></p>
    </FORM>
    Attached Files Attached Files

  5. #20
    Join Date
    Nov 2007
    Posts
    43

    Re: CHttp... Post with "action"

    Hey, I'm working on a Upload tool So far i has been a succes thanks to this Thread. I've recently mad a GET request which work out great. But now i want to make a POST request. I know what kind of dat is being sent to the server. I only don't know how to fit all that data into 1 string. Here is the data that i want to Post:

    -----------------------------24822581126073
    Content-Disposition: form-data; name="stage"

    2
    -----------------------------24822581126073
    Content-Disposition: form-data; name="username"

    admin
    -----------------------------24822581126073
    Content-Disposition: form-data; name="password"

    1234
    -----------------------------24822581126073
    Content-Disposition: form-data; name="title"

    Kill
    -----------------------------24822581126073
    Content-Disposition: form-data; name="tags"

    Kill
    -----------------------------24822581126073
    Content-Disposition: form-data; name="comment"

    Kill test
    -----------------------------24822581126073
    Content-Disposition: form-data; name="password"; filename="kill.txt"
    Content-Type: text/plain

    kill
    -----------------------------24822581126073--

    Thanks,

    Bami

  6. #21
    Join Date
    Feb 2003
    Location
    California
    Posts
    334

    Re: CHttp... Post with "action"

    You don't have to do anything to 'make it into one string.' Just change the form action type to POST.
    Henri Hein
    Principal Engineer, Propel
    Do not credit Propel with my views or opinions.

  7. #22
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,556

    Re: CHttp... Post with "action"

    [Use code tags when posting code]
    Quote Originally Posted by Bamirasta
    ... I have trouble with converting the dwRead to String.
    I think you are referring to this line, which the compiler is (hopefully) choking on:
    Code:
    str = dwRead; // str is a CString
    Try this:
    Code:
    str.Format( T("%d), dwRead );
    Note that if you are compiling a Unicode build, the resulting string will be Unicode and might not look like what you expect.

    Mike

  8. #23
    Join Date
    Nov 2007
    Posts
    43

    Unhappy Re: CHttp... Post with "action"

    Ok, what do you suggest me to do. But what am exactly suppose to send? The amount of bytes read?
    Am i suppose to send this:

    Content-Disposition: form-data; name="password"; filename="[file]"
    Content-Type: text/plain

    filecontent
    -----------------------------177603185628345--
    Last edited by Bamirasta; December 2nd, 2007 at 03:29 PM.

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured