----- Original Message -----
From: Hrvoje Niksic <[EMAIL PROTECTED]>
To: Will Fish <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Monday, April 30, 2001 7:32 PM
Subject: Re: "POST" encoding


> "Will Fish" <[EMAIL PROTECTED]> writes:
>
> > I recently wanted to send info to a cgi script in POST encoded
> > format, I found that the version of wget I had on suse6.4 only
> > supports GET (url encoded) so wrote a quick hack to send url encoded
> > wget commands in post format I added this as a -M switch. I just
> > thought I would let the mailing list know In case anyone else
> > requires this function and wants a copy of the patch.
>
> This feature is very requested, so it will definitely go in, sooner or
> later.  Several patches for POST have been floating around, but I
> wasn't completely satisfied with any of them.  Please send in yours to
> <[EMAIL PROTECTED]>.
>

1/5/01
from: [EMAIL PROTECTED]

This is the wget POST patch that I wrote yesterday afternoon. It is for
wget-1.5.3 as distributed in suse linux 6.4. It was created using: diff -cr
wget-1.5.3 wget-1.5.3.new > wget-post.patch

This is a very quick hack really I did it coz I thought that wget didnt
support POST encoding and needed it. I basically just greped for 'GET' in
the code, found that it was handled in the http.c file, added a proc to
strip the POST data from the URL encoded GET form and modified the way the
http request was sprint'ed, I then added a global var(post), command line
switch(-M) in main.c to change a GET URL to a POST. I must admit I have not
really examined the original code to any degree and the patch is just a very
quick bolt on sort of hack(it took about an hour), it seems to work for me
but may be totally useless for others????

regards

>>>>>>>>>>>>>>>>> CUT TEXT BELOW LINE AND SAVE AS wget-post.patch

Only in wget-1.5.3.new/src: config.h
diff -cr wget-1.5.3/src/http.c wget-1.5.3.new/src/http.c
*** wget-1.5.3/src/http.c Thu Sep 10 14:14:44 1998
--- wget-1.5.3.new/src/http.c Tue May  1 10:42:09 2001
***************
*** 287,292 ****
--- 287,309 ----

  static time_t http_atotm PARAMS ((char *));

+
+ char * PostStripURL(char *path)
+ {
+   int i=0;
+
+   while(path[i]!='\0'){
+     if(path[i]=='?'){
+       path[i]='\0';
+       return((char *) &path[i+1] );
+     }
+  i++;
+   }
+
+   return(NULL);
+ }
+
+
  /* Retrieve a document through HTTP protocol.  It recognizes status
     code, and correctly handles redirections.  It closes the network
     socket.  If it receives an error from the functions below it, it
***************
*** 316,321 ****
--- 333,339 ----
    FILE *fp;
    int auth_tried_already;
    struct rbuf rbuf;
+   char *post_data;

    /* Let the others worry about local filename...  */
    if (!(*dt & HEAD_ONLY))
***************
*** 467,472 ****
--- 485,491 ----
         + (opt.user_header ? strlen (opt.user_header) : 0)
         + 64);
    /* Construct the request.  */
+   //  if(post)
    sprintf (request, "\
  %s %s HTTP/1.0\r\n\
  User-Agent: %s\r\n\
***************
*** 480,485 ****
--- 499,524 ----
     range ? range : "",
     pragma_h,
     opt.user_header ? opt.user_header : "");
+   if(post){
+   post_data=PostStripURL(path);
+   sprintf (request, "\
+ %s %s HTTP/1.0\r\n\
+ User-Agent: %s\r\n\
+ Host: %s:%d\r\n\
+ Accept: %s\r\n\
+ Content-length: %i\n\
+ Content-type: application/x-www-form-urlencoded\n\n\
+ %s
+ %s%s%s%s%s%s\r\n",
+     "POST", path, useragent, remhost, remport, HTTP_ACCEPT,
strlen(post_data),post_data,
+    referer ? referer : "",
+    wwwauth ? wwwauth : "",
+    proxyauth ? proxyauth : "",
+    range ? range : "",
+    pragma_h,
+    opt.user_header ? opt.user_header : "");
+   }
+
    DEBUGP (("---request begin---\n%s---request end---\n", request));
     /* Free the temporary memory.  */
    FREE_MAYBE (wwwauth);
diff -cr wget-1.5.3/src/main.c wget-1.5.3.new/src/main.c
*** wget-1.5.3/src/main.c Fri Sep 11 02:41:53 1998
--- wget-1.5.3.new/src/main.c Tue May  1 10:42:10 2001
***************
*** 120,125 ****
--- 120,126 ----
    -h,  --help              print this help.\n\
    -b,  --background        go to background after startup.\n\
    -e,  --execute=COMMAND   execute a `.wgetrc\' command.\n\
+   -M,  --use-post          post data instead of url encoded
  \n"), _("\
  Logging and input file:\n\
    -o,  --output-file=FILE     log messages to FILE.\n\
***************
*** 199,204 ****
--- 200,206 ----

    static struct option long_options[] =
    {
+     { "use-post",  no_argument, NULL, 'M' },
      { "background", no_argument, NULL, 'b' },
      { "continue", no_argument, NULL, 'c' },
      { "convert-links", no_argument, NULL, 'k' },
***************
*** 282,292 ****
  #ifdef WINDOWS
    windows_main_junk (&argc, (char **) argv, (char **) &exec_name);
  #endif
!
    initialize ();

    while ((c = getopt_long (argc, argv, "\
! hVqvdksxmNWrHSLcFbEY:g:T:U:O:l:n:i:o:a:t:D:A:R:P:B:e:Q:X:I:w:",
        long_options, (int *)0)) != EOF)
      {
        switch (c)
--- 284,294 ----
  #ifdef WINDOWS
    windows_main_junk (&argc, (char **) argv, (char **) &exec_name);
  #endif
!   post=0;
    initialize ();

    while ((c = getopt_long (argc, argv, "\
! hVqvdksxmNMWrHSLcFbEY:g:T:U:O:l:n:i:o:a:t:D:A:R:P:B:e:Q:X:I:w:",
        long_options, (int *)0)) != EOF)
      {
        switch (c)
***************
*** 333,338 ****
--- 335,344 ----
     break;
   case 22:
     setval ("simplehostcheck", "on");
+    break;
+  case 'M':
+    fprintf(stderr,"\n\n\test\n\n");
+    post=1;
     break;
   case 'b':
     setval ("background", "on");
diff -cr wget-1.5.3/src/wget.h wget-1.5.3.new/src/wget.h
*** wget-1.5.3/src/wget.h Sat Jun 13 05:52:54 1998
--- wget-1.5.3.new/src/wget.h Tue May  1 10:42:14 2001
***************
*** 36,41 ****
--- 36,46 ----
  # endif
  #endif

+ #ifndef POST_USE
+ # define POST_USE
+ int post;
+ # endif
+
  /* `gettext (FOO)' is long to write, so we use `_(FOO)'.  If NLS is
     unavailable, _(STRING) simply returns STRING.  */
  #ifdef HAVE_NLS


Reply via email to