Need help with this function.
The goal is to bypass the web form and load the resulting table direct to a field.
Modified the PostDataToURL function to include the additional parameters, just hardcoded.
The script returns ERROR.
FM11 Adv, MAC
Thanks in advance!
Calling script.
PostDataToURLxx( "FFX" ; "2" ; http://aa.usno.navy.mil/cgi-bin/aa_rstablew.pl )
Registration script.
RegisterGroovy( "PostDataToURLxx( key ; value ; url )" ; "// Construct data¶
String data = URLEncoder.encode(key, \"UTF-8\") + \"=\" + URLEncoder.encode(value, \"UTF-8\");¶
// use something like the following to send multiple key/value pairs¶
data += \"&\" + URLEncoder.encode(xxy, \"UTF-8\") + \"=\" + URLEncoder.encode(2012, \"UTF-8\");¶
data += \"&\" + URLEncoder.encode(type, \"UTF-8\") + \"=\" + URLEncoder.encode(0, \"UTF-8\");¶
data += \"&\" + URLEncoder.encode(place, \"UTF-8\") + \"=\" + URLEncoder.encode(Sparta, \"UTF-8\");¶
data += \"&\" + URLEncoder.encode(xx0, \"UTF-8\") + \"=\" + URLEncoder.encode(-1, \"UTF-8\");¶
data += \"&\" + URLEncoder.encode(xx1, \"UTF-8\") + \"=\" + URLEncoder.encode(93, \"UTF-8\");¶
data += \"&\" + URLEncoder.encode(xx2, \"UTF-8\") + \"=\" + URLEncoder.encode(6, \"UTF-8\");¶
data += \"&\" + URLEncoder.encode(yy0, \"UTF-8\") + \"=\" + URLEncoder.encode(1, \"UTF-8\");¶
data += \"&\" + URLEncoder.encode(yy1, \"UTF-8\") + \"=\" + URLEncoder.encode(37, \"UTF-8\");¶
data += \"&\" + URLEncoder.encode(yy2, \"UTF-8\") + \"=\" + URLEncoder.encode(2, \"UTF-8\");¶
data += \"&\" + URLEncoder.encode(zz1, \"UTF-8\") + \"=\" + URLEncoder.encode(6, \"UTF-8\");¶
data += \"&\" + URLEncoder.encode(zz0, \"UTF-8\") + \"=\" + URLEncoder.encode(-1, \"UTF-8\");¶
data += \"&\" + URLEncoder.encode(ZZZ, \"UTF-8\") + \"=\" + URLEncoder.encode(END, \"UTF-8\")¶
¶
// Send data¶
URL url = new URL(url);¶
URLConnection conn = url.openConnection();¶
conn.setDoOutput(true);¶
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());¶
wr.write(data);¶
wr.flush();¶
¶
// Get the response¶
String response = conn.getInputStream().getText(\"utf-8\");¶
wr.close();¶
return response;"; "isGui=false" )
= "ERROR"
The website with the form.
http://aa.usno.navy..../RS_OneYear.php
Here is just the form from the source.
<a name="formb"></a>
<h3 style="color: red; border-top: 1px solid black; margin-top: 1em; padding-top: 1em;">Form B - Locations Worldwide</h3>
<h2>Specify year, type of table, and place:</h2>
<form method="post" target="_parent" action="http://aa.usno.navy....a_rstablew.pl">
<input type="hidden" name="FFX" value="2">
<p>
<span class="bold"><label for="xxy_int">Year:</label></span> <input type="text" name="xxy" id="xxy_int" size="4" maxlength="4" value="2012">
<label for="tabtyb"><b>Type of table:</b></label> <select name="type" id="tabtyb">
<option selected value="0">sunrise/sunset</option>
<option value="1">moonrise/moonset</option>
<option value="2">civil twilight</option>
<option value="3">nautical twilight</option>
<option value="4">astronomical twilight</option>
</select></p>
<span class="bold"><label for="placeint">Place Name Label:</label></span>
<input type="text" name="place" id="placeint" size="32" maxlength="32" value="(no name given)">
<p>The place name you enter above is merely a label for the table header;
you can enter any identifier, or none (avoid using punctuation characters).
The data will be calculated for the longitude and latitude you enter below. </p>
<fieldset><legend><b>Longitude:</b></legend>
<input type="radio" name="xx0" id="east" value="1"> <label for="east">east</label>
<input type="radio" name="xx0" id="west" checked value="-1"> <label for="west">west</label>
<input type="text" name="xx1" id="dego" size="3" maxlength="3" value=""> <label for="dego">degrees</label>
<input type="text" name="xx2" id="mino" size="2" maxlength="2" value=""> <label for="mino">minutes</label>
</fieldset>
<fieldset><legend><b>Latitude:</b></legend>
<input type="radio" name="yy0" id="north" checked value="1"> <label for="north">north</label>
<input type="radio" name="yy0" id="south" value="-1"> <label for="south">south</label>
<input type="text" name="yy1" id="dega" size="2" maxlength="2" value=""> <label for="dega">degrees</label>
<input type="text" name="yy2" id="mina" size="2" maxlength="2" value=""> <label for="mina">minutes</label>
</fieldset>
<fieldset><legend><b>Time Zone:</b></legend>
<input type="text" name="zz1" id="zhour" size="5" maxlength="5"> <label for="zhour">hours</label>
<input type="radio" name="zz0" id="zeast" value="1"> <label for="zeast">east of Greenwich</label>
<input type="radio" name="zz0" id="zwest" checked value="-1"> <label for="zwest">west of Greenwich</label>
</fieldset>
<p>For locations that require it, the time zone can be entered in hours and a
fraction. For example, for locations in India, the time zone may be entered
as 5.5 hours east of Greenwich. The time zone field can accommodate up to
five characters.</p>
Need coordinates? Try NGA's
<a href="http://earth-info.ng...tml/index.html" target="blank">GEOnet
Names Server (GNS)</a>.
<br>Need U.S. coordinates? Try the USGS
<a href="http://geonames.usgs...ls/gnispublic/" target="blank">Geographic Names Information System (GNIS)</a>.
<br>
Need a time zone? Try the <a href="faq/docs/world_tzones.php">time zone map</a>.
<input type="hidden" name="ZZZ" value="END">
<p><input type="submit" value="Compute Table">
<input type="reset" value="Clear all fields"></p>
</form>