I am trying to do a search on a government website to obtain what
is called a National Stock Number (NSN).
Manually, it works like this...
Navigate to https://www.dlis.dla.mil/WebFlis/pub/pub_search.aspx.
Enter part number 59250 in the Part Number field and click GO.
It should return a page with this information on it:
Part Number CAGE Code Item Name NSN
59250 53655 PULL CABLE ASSY 1660004610707
59250 D8512 CRIMPING TOOL,TERMINAL,HAND 5120006862046
59250 00779 CRIMPING TOOL,TERMINAL,HAND 5120006862046
59250 84134 TOOL,CRIMPING 5120010611349
59250 99167 RETAINER,PACKING 5330012785284
59250 00779 CRIMPING TOOL,TERMINAL,HAND 5120015276963
I am having trouble getting to this page using the code below.
Is it because it is an ASP.Net page that is causing the problem?
I am getting the VIEWSTATE and EVENTVALIDATION values and
posting them along with the other values but I still cannot get
to that page.
Funny thing is, the links to the NSN's are the same URL with get parameters, i.e.
https://www.dlis.dla.mil/WebFlis/pub/pub_search.aspx?niin=1660004610707&newpage=1
Believe me, I've tried a bunch of different combinations to try to pass the part number in a GET.
Can anyone help out here?
<?
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_URL, "https://www.dlis.dla.mil/WebFlis/pub/pub_search.aspx");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$returned = curl_exec($ch);
$doc = new DOMDocument();
$doc->loadHTML($returned);
$nodes = $doc->getElementsByTagName('input');
for($i=0; $i<$nodes->length; $i++) {
if ($nodes->item($i)->getAttribute('name') == "__VIEWSTATE" ) {
$viewstate = $nodes->item($i)->getAttribute('value');
}
if ($nodes->item($i)->getAttribute('name') == "__EVENTVALIDATION" ) {
$eventvalidation = $nodes->item($i)->getAttribute('value');
}
}
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_URL, "https://www.dlis.dla.mil/WebFlis/pub/pub_search.aspx");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('__VIEWSTATE'=>$viewstate,
'__EVENTVALIDATION'=>$eventvalidation,
'txtNiin'=>'',
'txtKeyword'=>'',
'txtPART'=>'59250',
'txtCAGE'=>'',
'chkCage'=>'',
'txtManName'=>'',
'txtManPartNum'=>'',
'C1'=>'checked',
'C3'=>'',
'C6'=>'checked',
'C4'=>'checked',
'C7'=>'',
'C9'=>''));
$returned = curl_exec($ch);
if (!$returned) {
echo curl_error($ch);
}
curl_close($ch);
echo $returned;
?>