-1

I get the following error, when i run my script.

fetch_scores.rb:20:in `<main>': undefined local variable or method `__EVENTTARGET' for    main:Object (NameError)

Hereś the script:

#fetch_scores.rb
require 'net/http'
require 'open-uri'

#define a constant named URL so if the results URL changes we don't
#need to replace a hardcoded URL everywhere.
URL = "http://www.nitt.edu/prm/nitreg/ShowRes.aspx"

#checking the count of arguments passed to the script.
#it is only taking one, so let's show the user how to use
#the script
if ARGV.length != 1
  puts "Usage: fetch_scores.rb student_name"
else
  roll_no = ARGV[0] #could drop the ARGV length check and add a default using ||
  # or   name = ARGV[0] || nikhil
end

params = {
  __EVENTTARGET => "Dt1",
  __EVENTARGUMENT =>  "",
  __VIEWSTATE => "dDwtMTM3NzI1MDM3O3Q8O2w8aTwxPjs+O2w8dDw7bDxpPDE+O2k8Mj47aTw0Pjs+O2w8dDxwPHA8bDxWaXNpYmxlOz47bDxvPHQ+Oz4+Oz47bDxpPDE+O2k8Mz47PjtsPHQ8O2w8aTwwPjtpPDE+O2k8Mj47aTwzPjtpPDQ+O2k8NT47aTw2Pjs+O2w8dDw7bDxpPDA+Oz47bDx0PDtsPGk8MT47PjtsPHQ8cDxwPGw8VGV4dDs+O2w8VEhJUkQgU0VNRVNURVIgTUFTVEVSIE9GIENPTVBVVEVSIEFQUExJQ0FUSU9OUyBOT1YtMjAxMChSRUdVTEFSKTs+Pjs+Ozs+Oz4+Oz4+O3Q8O2w8aTwxPjs+O2w8dDw7bDxpPDE+Oz47bDx0PHA8cDxsPFRleHQ7PjtsPFNVREVFUCBBR0FSV0FMOz4+Oz47Oz47Pj47Pj47dDw7bDxpPDE+Oz47bDx0PDtsPGk8MT47PjtsPHQ8cDxwPGw8VGV4dDs+O2...xwPGw8VGV4dDs+O2w8MTk7Pj47Pjs7Pjs+Pjs+Pjt0PDtsPGk8MT47PjtsPHQ8O2w8aTwxPjs+O2w8dDxwPHA8bDxUZXh0Oz47bDwwOz4+Oz47Oz47Pj47Pj47Pj47dDxwPHA8bDxWaXNpYmxlOz47bDxvPGY+Oz4+Oz47Oz47Pj47dDw7bDxpPDk+O2k8MTE+Oz47bDx0PHA8cDxsPFRleHQ7VmlzaWJsZTs+O2w8U2VsZWN0IFNlc3Npb24gICA7bzx0Pjs+Pjs+Ozs+O3Q8dDxwPHA8bDxWaXNpYmxlOz47bDxvPHQ+Oz4+Oz47dDxpPDM+O0A8LSBTZWxlY3QgLTtOT1YtMjAxMChSRUdVTEFSKTtNQVktMjAxMVtSRUdVTEFSXTs+O0A8MDs2Mjs2Njs+PjtsPGk8MT47Pj47Oz47Pj47dDxwPHA8bDxUZXh0Oz47bDxcZTs+Pjs+Ozs+Oz4+Oz4+Oz53I0hrrJ9pq04wIekH/y79mq+lYQ==",
  TextBox1 => roll_no,
  Dt1 => 66
}

results = Net::HTTP.post_form( URL, params ) 
p results
nikhil
  • 8,925
  • 21
  • 62
  • 102

1 Answers1

1

__EVENTTARGET in the params hash is parsed as a variable and that variable was never defined. Try "__EVENTTARGET" => "Dt1".

Jonas Elfström
  • 30,834
  • 6
  • 70
  • 106
  • Youŕe right about that. This is the new error that i get now, /home/nikhil/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/net/http.rb:415:in `post_form': undefined method `path' for "http://www.nitt.edu/prm/nitreg/ShowRes.aspx":String (NoMethodError) from fetch_scores.rb:27:in `
    '
    – nikhil Jun 07 '11 at 11:14
  • I fixed that error by changing the URL to URL = URI.parse('http://www.nitt.edu/prm/nitreg/ShowRes.aspx') Now i get this error # Iḿ new to ruby so this is all new to me. – nikhil Jun 07 '11 at 11:19
  • You have actually answered my original question, So i should choose your answer but if you could help me with this it would be much appreciated. – nikhil Jun 07 '11 at 11:22
  • The `HTTPInternalServerError 500` isn't an error in your script but an error from the server you are posting to. – Jonas Elfström Jun 07 '11 at 12:12
  • You could take a look at Mechanize http://mechanize.rubyforge.org/mechanize/GUIDE_rdoc.html – Jonas Elfström Jun 07 '11 at 12:14