0

There is this website https://www.bricklink.com/catalogDownload.asp which should download a .xml or .txt file automatically if the link is called. The only problem is, that it seems like you must be logged in to call that link. My goal is to write a piece of code which automatically fills the login form and afterwards calls the link again to download the file. My two main problems are to get how to fill the two login parameters and how to make sure I am still logged in afterwards in order to be able to download the file.

My first approach looks like this:

 $postdata = http_build_query(
        array(
            'frmUsername' => 'myUsername',
            'frmPassword' => 'myPassword'
        )
    ); 
    $opts = array('http' =>
        array(
            'method'  => 'POST',
            'header'  => 'Content-type: application/x-www-form-urlencoded',
            'content' => $postdata
        )
    );
    
    $context  = stream_context_create($opts);
    
    $result = file_get_contents('https://bricklink.com/catalogdownload.asp', false, $context);
    print_r($result);

Firstly, I am creating the httpRequest-body and secondly, I am calling the url mentioned above.

M. Eriksson
  • 13,450
  • 4
  • 29
  • 40
ForzaJuve
  • 75
  • 1
  • 8
  • Welcome. You need to do the [appropriate amount of research](https://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users) and make some attempts yourself first. If you get stuck on something _specific_, post your attempt, explain where you're stuck, the expected result and what currently happens. We're here to help you with concrete issues with your current code, not to write it all for you (which a proper answer here would require us to). – M. Eriksson Feb 15 '22 at 07:01
  • Also read [How to create a Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) and [how to ask](https://stackoverflow.com/help/how-to-ask). You should also [take the tour](https://stackoverflow.com/tour) that was recommended to you when you registered. – M. Eriksson Feb 15 '22 at 07:02
  • Updated my question, hope this helps to understand my needs a little bit better. – ForzaJuve Feb 15 '22 at 07:37
  • Check if this post helps you (using cURL instead of file_get_contents): https://stackoverflow.com/questions/3008817/login-to-remote-site-with-php-curl - You need to store the cookie you get when logging in and pass it to each request after. – M. Eriksson Feb 15 '22 at 10:14
  • Thank you for providing the link, I will take a look at it. – ForzaJuve Feb 17 '22 at 08:37
  • 1
    @M.Eriksson tried the solution from the link - works fine now, thank you! Probably need to dig a little bit deeper into the cookie topic. – ForzaJuve Feb 17 '22 at 21:40

0 Answers0