cuRL returnin 404 error

后端 未结 3 1539
猫巷女王i
猫巷女王i 2020-12-06 11:23

I`m using cuRL to get some data from remote server... The response is in JSON format.. This is my code:

$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0         


        
3条回答
  •  Happy的楠姐
    2020-12-06 12:20

    Probably there is something else the browser is sending your cURL code is not. You can use any of the tools other folks have suggested, Firebug, Wireshark, Fiddler, etc, etc.

    What you need to do is add missing pieces to your request to match the browser as closely as possible in the cURL request until the remote page responds with a 200.

    I notice you're doing a POST. In many cases what happens with your browser is you visit a page with a GET request. A session is initialized on the remote site and a cookie is saved in your browser with the session id.

    This cookie then needs to be supplied along with subsequent POST requests. PHP cURL has many options to support cookies. There may be other requirements such as CSRF tokens and so forth.

    Again, reverse-engineering is the key.

提交回复
热议问题