Can open PSE API using browser but not using PHP -


i'm trying record data philippine stock exchange website. have found have endpoint http://www.pse.com.ph/stockmarket/companyinfo.html?method=fetchheaderdata&company=29&security=146

i can access using browsers except when go incognito mode i'm being shown content saying access denied , never stops loading. when try access using php i'm quite sure happening same later.

i'm trying access using php no avail, here attempts tried:

  1. file_get_contents
  2. curl user agent
  3. curl temporary cookies
  4. tried in localhost , in live server.

code:

$c = tempnam ("/tmp", "curlcookie"); $ch = curl_init(); curl_setopt($ch, curlopt_url, "http://www.pse.com.ph/stockmarket/companyinfo.html"); curl_setopt($ch, curlopt_ssl_verifypeer, false); curl_setopt($ch, curlopt_cookiesession, true ); curl_setopt($ch, curlopt_cookiejar, $c); curl_setopt($ch, curlopt_cookiefile, $c); curl_setopt($ch, curlopt_postfields, "method=fetchheaderdata&ajax=true&company=29&security=146"); curl_setopt($ch, curlopt_useragent, $_server["http_user_agent"]); curl_setopt($ch, curlopt_returntransfer, true); var_dump(curl_exec($ch)); curl_close ($ch); 

i don't have clear idea on why , how happen. can explain me why happens , possible solutions (php if possible)

i have reviewed other developer's approach on api (they implemented using java) , simple post request , done. have not verified though if code still working. can't post links repository (limited).


solutions:

problem 1. can't access api

$posts = array(   "method"=>"fetchheaderdata",   "ajax"=>"true",   "company"=>29,   "security"=>146 ); $ch = curl_init(); curl_setopt($ch, curlopt_url, "http://www.pse.com.ph/stockmarket/companyinfo.html"); curl_setopt($ch, curlopt_postfields,$posts); curl_setopt($ch, curlopt_returntransfer, true); var_dump(curl_exec($ch)); curl_close ($ch); 

it seems have 2 different problems. can access , use api using code above. no need other options. turning post data array fixed problem.

problem 2. access denied

on problem access denied, cookie related. answered below @wayne.


unfortunately, can't accept 2 answers.

try solution. convert post data in array pass array in curlopt_postfields

$posts = array(   "method"=>"fetchheaderdata",   "ajax"=>"true",   "company"=>29,   "security"=>146   ); $c = tempnam ("/tmp", "curlcookie"); $ch = curl_init(); curl_setopt($ch, curlopt_url, "http://www.pse.com.ph/stockmarket/companyinfo.html"); curl_setopt($ch, curlopt_ssl_verifypeer, false); curl_setopt($ch, curlopt_cookiesession, true ); curl_setopt($ch, curlopt_cookiejar, $c); curl_setopt($ch, curlopt_cookiefile, $c); curl_setopt($ch, curlopt_postfields,$posts); curl_setopt($ch, curlopt_useragent, $_server["http_user_agent"]); curl_setopt($ch, curlopt_returntransfer, true); var_dump(curl_exec($ch)); curl_close ($ch); 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -