Loading ...
Sorry, an error occurred while loading the content.
 

Bad url

Expand Messages
  • Jean Saint-Remy
    Hi, I am able to generate Bad URL error using the call surlml http://www.yahoo.com with the code snippet below. I am using Gerd s ocamlnet-3.6.3 compiled
    Message 1 of 1 , Jan 26, 2013
      Hi,


      I am able to generate "Bad URL" error using the call 'surlml "http://www.yahoo.com"' with the code snippet below. I am using Gerd's ocamlnet-3.6.3 compiled with ocaml 4.00.1. It works fine with the simple routine 'get_and_print "http://www.yahoo.com"'. As far as I can tell, the requested url should be a string, but I get the pesky error message whether I use http://www.yahoo.com or stripped version www.yahoo.com with or without quotes. I get the same with "http://www.yahoo.com/index.html". Am I missing some parsing library then? It's the same Convenience method in both cases.

      With kind regards,

      jean

      (* http_get.ml *)
      #use "topfind" ;;
      #require "netclient" ;;
      open Http_client.Convenience ;;

      let get_and_print url =
        let s = http_get url in 
        print_string s;
        flush stdout
      ;;
      (* ------------------------------------------------------------- *)

      #!/usr/bin/ocaml
      (* surl.ml *)
      (* chmod 0755 surl.ml *)
      #use "topfind" ;;
      #require "netclient" ;;

      open Http_client.Convenience

      let dates = ref [] 

      let () = 
        try
          while true do
             let url = input_line stdin in
             let call = http_head_message url in 
             let date =
               try Some (Netdate.parse
                                  (call#response_header#field "Last-Modified"))
               with Not_found -> None in
            dates := (date,url) :: !dates
         done
      with End_of_file -> ()

      let () = 
        List.iter
          (fun (date,url) -> 
             Printf.printf "%-25s %s\n"
               (match date with
                  | Some date -> Netdate.format "%a %b %d %H:%M:%S %Y" date
                  | None        -> "<NONE SPECIFIED>")
               url)
      (List.rev (List.sort compare !dates))

      [Non-text portions of this message have been removed]
    Your message has been successfully submitted and would be delivered to recipients shortly.