Results 1 to 10 of 10

Thread: Curl / http / cookie ? / message

  1. #1
    Join Date
    Jun 2008
    Location
    France
    Posts
    41

    Default Curl / http / cookie ? / message

    Hi,

    I'm trying to post a message in a forum using cURL and I wonder only if it is possible. For example :

    Code:
    <textarea class="userform" name="message" rows="12" cols="80"></textarea>
    
    						</td>
    					</tr>
    										<tr>
    						<td class="default">
    							&nbsp;
    						</td>
    						<td class="default">
    							<input class="userform" value="Post this message" name="valid" accesskey="S" type="submit"> <input class="userform" value="Preview this post" name="preview" accesskey="P" type="submit">
    I try several things like (1 is a file which contains the text I want to write in the textarea):

    Code:
    curl -b keyforum=valuecookie -F "userform=@1" <submit URL forum>
    but it never works. Sometimes I get the source-code of the page, sometimes I get an error message like curl: (26) failed creating formpost data

    Could you help me understanding if this kind of operation is possible, and where do I make a mistake

    thanks.
    OpenSuse 11.1 - KDE 4.2.0 "release 100" - 2.6.27.7-9-default - Intel Pentium 4 3 GHz - Asus P4P800 SE - 1Go DDR SDRAM - ATI Radeon 9600 SERIES - Creative EMU10K1SB Live Audio Processor - 802.11g PCI Wireless Network Adapter - Samsung Syncmaster 931BW

  2. #2
    ab@novell.com NNTP User

    Default Re: Curl / http / cookie ? / message

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    Do you have a URL we could actually use and play with? I guess that's a
    little risky but it would help.

    Good luck.






    pc54g2 wrote:
    | Hi,
    |
    | I'm trying to post a message in a forum using cURL and I wonder only if
    | it is possible. For example :
    |
    |
    | Code:
    | --------------------
    | <textarea class="userform" name="message" rows="12"
    cols="80"></textarea>
    |
    | </td>
    | </tr>
    | <tr>
    | <td class="default">
    | &nbsp;
    | </td>
    | <td class="default">
    | <input class="userform" value="Post this message"
    name="valid" accesskey="S" type="submit"> <input class="userform"
    value="Preview this post" name="preview" accesskey="P" type="submit">
    | --------------------
    |
    |
    | I try several things like (1 is a file which contains the text I want
    | to write in the textarea):
    |
    |
    | Code:
    | --------------------
    | curl -b keyforum=valuecookie -F "userform=@1" <submit URL forum>
    | --------------------
    |
    |
    | but it never works. Sometimes I get the source-code of the page,
    | sometimes I get an error message like -curl: (26) failed creating
    | formpost data-
    |
    | Could you help me understanding if this kind of operation is possible,
    | and where do I make a mistake
    |
    | thanks.
    |
    |
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.2 (GNU/Linux)
    Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

    iD8DBQFInbKX3s42bA80+9kRAm5JAJ4zG2MX7ZF3145qitEXDApmwRcAUgCfWGOB
    fTwPh26lTq0cjssKhX/Rllk=
    =M2td
    -----END PGP SIGNATURE-----

  3. #3
    Join Date
    Jun 2008
    Location
    France
    Posts
    41

    Default Re: Curl / http / cookie ? / message

    Thanks ab@novell.com

    well... I don't have specific URL, in fact... why not here :

    Code:
    <input name="do" value="postreply" type="hidden">
    I just want to know what could be the correct syntax using cURL to post a reply in a forum
    OpenSuse 11.1 - KDE 4.2.0 "release 100" - 2.6.27.7-9-default - Intel Pentium 4 3 GHz - Asus P4P800 SE - 1Go DDR SDRAM - ATI Radeon 9600 SERIES - Creative EMU10K1SB Live Audio Processor - 802.11g PCI Wireless Network Adapter - Samsung Syncmaster 931BW

  4. #4
    ab@novell.com NNTP User

    Default Re: Curl / http / cookie ? / message

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    Did you notice that an '@' is a special character when in the form data
    at the beginning of the form data? From the curl manpage:

    <quote>
    - -F/--form <name=content>
    ~ (HTTP) This lets curl emulate a filled in form in which a
    user has pressed the submit button. This causes curl to POST data using
    the Con‐
    ~ tent-Type multipart/form-data according to RFC1867. This
    enables uploading of binary files etc. To force the 'content' part to be
    a file,
    ~ prefix the file name with an @ sign. To just get the
    content part from a file, prefix the file name with the letter <.
    The difference
    ~ between @ and < is then that @ makes a file get attached
    in the post as a file upload, while the < makes a text field and just
    get the con‐
    ~ tents for that text field from a file.

    ~ Example, to send your password file to the server, where
    'password' is the name of the form-field to which /etc/passwd will be
    the input:

    ~ curl -F password=@/etc/passwd www.mypasswords.com

    ~ To read the file's content from stdin instead of a file,
    use - where the file name should've been. This goes for both @ and <
    constructs.

    ~ You can also tell curl what Content-Type to use by using
    'type=', in a manner similar to:

    ~ curl -F "web=@index.html;type=text/html" url.com

    ~ or

    ~ curl -F "name=daniel;type=text/foo" url.com

    ~ You can also explicitly change the name field of an file
    upload part by setting filename=, like this:

    ~ curl -F "file=@localfile;filename=nameinpost" url.com

    ~ See further examples and details in the MANUAL.
    </quote>

    Good luck.





    pc54g2 wrote:
    | Thanks ab@novell.com
    |
    | well... I don't have specific URL, in fact... why not here :
    |
    |
    | Code:
    | --------------------
    | <input name="do" value="postreply" type="hidden">
    | --------------------
    |
    |
    | I just want to know what could be the correct syntax using cURL to
    | post a reply in a forum
    |
    |
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.2 (GNU/Linux)
    Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

    iD8DBQFInn8r3s42bA80+9kRAmBJAJwKH8p4UHrdGVkpgoIlaDMZS3k+qwCcCz5y
    VCh85k6V3mlgMHRYXPj5RXc=
    =Fpfp
    -----END PGP SIGNATURE-----

  5. #5
    Join Date
    Jun 2008
    Location
    France
    Posts
    41

    Default Re: Curl / http / cookie ? / message

    Yes but anyway, the difficulty is to identify the values with curl's option. I tried too without using @, just writing a word.

    For example, to post in this thread :

    URL :

    Code:
    http://forums.opensuse.org/newreply.php?do=newreply&noquote=1&p=1854082
    I'm not sure, but I think it is necessary to substitue the character & with &&, so URL should become :

    Code:
    http://forums.opensuse.org/newreply.php?do=newreply&&noquote=1&&p=1854082
    Source code :

    Code:
    <input name="s" value="" type="hidden">
    		<input name="securitytoken" value="1218363100-e825f570a4ec2048fb5ee4d39974114dc0262d1f" type="hidden">
    		<input name="do" value="postreply" type="hidden">
    		<input name="t" value="392299" type="hidden">
    		<input name="p" value="1854082" type="hidden">
    		<input name="specifiedpost" value="0" type="hidden">
    		<input name="posthash" value="" type="hidden">
    
    		<input name="poststarttime" value="" type="hidden">
    		<input name="loggedinuser" value="786" type="hidden">
    		<input name="multiquoteempty" id="multiquote_empty_input" value="" type="hidden">
    		<input class="button" name="sbutton" id="vB_Editor_001_save" value="Submit Reply" accesskey="s" tabindex="1" type="submit">
    - do I have to specify my username & password ? if yes, and if it is correct, I will use the option :

    Code:
    -u pc54g2:password
    - do I have to specify cookie ? if yes, I'm not sure if the following choice is good :

    Code:
    -b "bbsessionhash=XXXX"
    bbics_login=true
    bbuserid=786
    bbusername=pc54g2
    bbpassword=password
    
    ...or other things from the cookies of this forum's
    - To simplify the problem, I just want to write "Hello" in this post, without using a file. Do I have to use the following parameters :

    Code:
    input name="s" value="" type="hidden"
    considering that "s" could be the message ? Or it is not necessary/correct to use one of this parameters from the source-code, like :

    Code:
    curl -d "Hello&other commands..."
    Finally, my command is something like :

    Code:
    curl -u pc54g2:password -b "bbsessionhash=xxx" -d "s=Hello&do=postreply&t=392299&p=1854082&loggedinuser=786&securitytoken=1218363100-e825f570a4ec2048fb5ee4d39974114dc0262d1f" http://forums.opensuse.org/newreply.php?do=newreply&&noquote=1&&p=1854082clear
    I made all theses tests after having seen this page cURL - Manual -> "POST (HTTP)"

    Have you tried to post here ?
    OpenSuse 11.1 - KDE 4.2.0 "release 100" - 2.6.27.7-9-default - Intel Pentium 4 3 GHz - Asus P4P800 SE - 1Go DDR SDRAM - ATI Radeon 9600 SERIES - Creative EMU10K1SB Live Audio Processor - 802.11g PCI Wireless Network Adapter - Samsung Syncmaster 931BW

  6. #6
    Join Date
    Jun 2008
    Location
    France
    Posts
    41

    Default Re: Curl / http / cookie ? / message

    Hi,

    I wonder if first the problem does not come from the special character & which is included in the URL of the post reply : do=newreply&noquote=1&p=1854082

    And substitute this character with 2 & does not change nothing. In fact the command :

    curl <URL>do=newreply&noquote=1&p=1854082
    does not download the good URL but the "root" of the forum (eg : instead of downloading <URL>do=newreply&noquote=1&p=1854082 it downloads htlp://forums.opensuse.org)

    Is there any way to "protect" this character, like we can do for example with special characters and sed or grep (backslash \ to protect special characters) ? I tried using '' or "" but the problem is the same. Note : With wget it works using "".

    Thank you
    OpenSuse 11.1 - KDE 4.2.0 "release 100" - 2.6.27.7-9-default - Intel Pentium 4 3 GHz - Asus P4P800 SE - 1Go DDR SDRAM - ATI Radeon 9600 SERIES - Creative EMU10K1SB Live Audio Processor - 802.11g PCI Wireless Network Adapter - Samsung Syncmaster 931BW

  7. #7
    Join Date
    Jun 2008
    Location
    France
    Posts
    41

    Default Re: Curl / http / cookie ? / message

    After sevral tests with curl without any success, I let fall.
    I would like to try with www::mechanize

    Code:
    mech-dump --forms "http://forums.opensuse.org/newreply.php?do=newreply&noquote=1&p=1854553"
    GET http://www.opensuse.org/index.php/Special:Search [searchform]
      search=                        (text)
      go=Go                          (image)
    
    POST https://forums.opensuse.org/ICSLogin/auth-up [login]
      url=http://forums.opensuse.org/newreply.php?do=newreply&noquote=1&p=1854553 (hidden readonly)
      context=default                (hidden readonly)
      proxypath=reverse              (hidden readonly)
      message=Please log In          (hidden readonly)
      username=                      (text)
      password=                      (password)
      submit=Log In                  (image)
    This script :

    Code:
    #!/usr/bin/perl
    use strict;
    use WWW::Mechanize;
    use HTTP::Cookies;
    my $mech = WWW::Mechanize->new;
    $mech->cookie_jar(
            HTTP::Cookies->new(
                file           => "/windows/C/Documents and Settings/pc54g2/Application Data/Mozilla/Firefox/Profiles/50d1pw8i.default/cookies.txt",
                autosave       => 1,
                ignore_discard => 1,
            )
        );
    use LWP::Debug qw(+);
    my $url = "http://forums.opensuse.org/newreply.php?do=newreply&noquote=1&p=1854553";
    $mech->get($url);
    $mech->submit_form(
                fields      => {
               username=>"pc54g2",
                password=>"xxx",
    	    message => "Hello",
                do => "postreply"
                },
    );
    $mech->submit()
    doesn't work but here is the response :

    Code:
    LWP::UserAgent::new: ()
    /windows/C/Documents and Settings/laza/Application Data/Mozilla/Firefox/Profiles/50d1pw8i.default/cookies.txt does not seem to contain cookies at /usr/lib/perl5/vendor_perl/5.10.0/HTTP/Cookies.pm line 427, <FILE> line 1.
    LWP::UserAgent::request: ()
    HTTP::Cookies::add_cookie_header: Checking forums.opensuse.org for cookies
    HTTP::Cookies::add_cookie_header: Checking .opensuse.org for cookies
    HTTP::Cookies::add_cookie_header: Checking opensuse.org for cookies
    HTTP::Cookies::add_cookie_header: Checking .org for cookies
    LWP::UserAgent::send_request: GET http://forums.opensuse.org/newreply.php?do=newreply&noquote=1&p=1854553
    LWP::UserAgent::_need_proxy: Not proxied
    LWP::Protocol::http::request: ()
    LWP::Protocol::collect: read 128 bytes
    LWP::UserAgent::request: Simple response: Found
    LWP::UserAgent::request: ()
    HTTP::Cookies::add_cookie_header: Checking forums.opensuse.org for cookies
    HTTP::Cookies::add_cookie_header: Checking .opensuse.org for cookies
    HTTP::Cookies::add_cookie_header: Checking opensuse.org for cookies
    HTTP::Cookies::add_cookie_header: Checking .org for cookies
    LWP::UserAgent::send_request: GET https://forums.opensuse.org/ICSLogin/?&#37;22http://forums.opensuse.org/newreply.php?do=newreply&noquote=1&p=1854553%22
    LWP::UserAgent::_need_proxy: Not proxied
    LWP::Protocol::http::request: ()
    LWP::Protocol::collect: read 856 bytes
    LWP::Protocol::collect: read 4096 bytes
    LWP::Protocol::collect: read 1332 bytes
    LWP::UserAgent::request: Simple response: OK
    No such field 'password' at /usr/lib/perl5/site_perl/5.10.0/WWW/Mechanize.pm line 1371
    Is it an authentification problem, or something else ?
    OpenSuse 11.1 - KDE 4.2.0 "release 100" - 2.6.27.7-9-default - Intel Pentium 4 3 GHz - Asus P4P800 SE - 1Go DDR SDRAM - ATI Radeon 9600 SERIES - Creative EMU10K1SB Live Audio Processor - 802.11g PCI Wireless Network Adapter - Samsung Syncmaster 931BW

  8. #8

    Default Gnome Permissions

    I apologize for posting here but I can't find where to start a new thread.

    My problem -- when I copy a file from a cd or dvd, it is locked by default. I know how to change the permissions, but is there a way to make all copied files in gnome automatically read-writable?

    In KDE, it is automatic. I don't need to unlock copied files.

    Any help would be great, I am using suse 11 gnome.

  9. #9
    ab@novell.com NNTP User

    Default Re: Curl / http / cookie ? / message

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    To create a new thread you'll need to tell us how you are connecting...
    HTTP (web interface), NNTP (Thunderbird, Pan, etc.). In Thunderbird you
    just click 'Write' and you have a new thread. Tada.

    If you are copying files from read-only media all files/directories from
    there come as read-only and you can change that easily enough.... doing
    so from the command line is also fairly easy with 'chmod' or the like.

    Good luck.





    allstar1960 wrote:
    > I apologize for posting here but I can't find where to start a new
    > thread.
    >
    > My problem -- when I copy a file from a cd or dvd, it is locked by
    > default. I know how to change the permissions, but is there a way to
    > make all copied files in gnome automatically read-writable?
    >
    > In KDE, it is automatic. I don't need to unlock copied files.
    >
    > Any help would be great, I am using suse 11 gnome.
    >
    >

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.2 (GNU/Linux)
    Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

    iD8DBQFI267T3s42bA80+9kRApqmAJ4+ZPDjO93gpJOvybFOsMjnTYvgegCdGneY
    8j6pq6I5r62Sr5hNfgIyET0=
    =bWKW
    -----END PGP SIGNATURE-----

  10. #10
    Join Date
    Jun 2008
    Location
    France
    Posts
    41

    Default Re: Curl / http / cookie ? / message

    Hi,

    I finally could post in three types of forum.
    I think if you want to do this, you need first to login in this forum and keep the cookie generated.
    The second thing which is important, once authentified, consists to post a reply and recording it using using some somtehing like LiveHTTPHeaders (this is a convenient plugin for Firefox).
    The log gives all the datas needed by the forum, and the URL you have to match. If you don't find every datas in this log, see the source-code of the webpage.

    So, post in a forum using Curl is possible.

    I hav'nt really tried with WWW::Mechanize, perl is too much hard for me, but it is certainly possible.

    bye
    OpenSuse 11.1 - KDE 4.2.0 "release 100" - 2.6.27.7-9-default - Intel Pentium 4 3 GHz - Asus P4P800 SE - 1Go DDR SDRAM - ATI Radeon 9600 SERIES - Creative EMU10K1SB Live Audio Processor - 802.11g PCI Wireless Network Adapter - Samsung Syncmaster 931BW

Posting Permissions

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