I recently had a project at my 9 to 5 that involved the need to combine several product XML data exports from an existing shopping cart and migrate them to a different shopping cart. The “different shopping cart” was written in classic ASP.

The Project Task List:

  • Combine several XML files to dump data into an adhoc created SQLite Database.
  • Post product data to existing classic ASP scripts that would handle putting the products into the new shopping cart automatically.
  • Post Data will include uploaded Image Data for an MSSQL database.

Is this how I would have liked to do this? No. But circumstances as they were it is what had to be done.

Everything was trucking along just fine until it came time to post the data to the classic ASP script running on some ancient version of IIS.

Using plain ole curl request parameters without a lot of extra header data was getting me NO WHERE.  I was getting a whole range of errors. (I put this post off for far too long so I don’t remember what errors I was getting or what sources I used to piece together my working functions.)  I had to post uploaded file data (for product images) and also just plain posted text data fields (title,descriptions,weight, price). Here are the functions I used for both.

I created a file called, “curlfunctions.php” that include these three functions.  I included it when I was looping through the product data queries from the SQLite database.

Function 1: CURLOPT_POSTFIELDS prep function

This function takes any array ($vars) and puts it into the linear separated (with “&”) string that CURL likes. In this case I just dumped in the whole $_POST array. Note: I did NOT use this function for the image posting. Just the text.

Function 2: addproduct() regular text fields

The trick with Classic ASP/IIS is all this extra header data. This is what worked for me to make the data accessible by the Classic ASP script through the Request.Form(“FormVariableHere”) array/struct/whatever they call it. THIS is only for the basic text data.

Function 3: addphoto() an uploaded file

The data I had for the product photo was an existing URL, not the actual file. So I had to download the photo to a temporary location and create the $data/$_POST array myself instead of using the postVars function from above. Also the headers changed a little bit in dealing with this new type of form data.

Of course all the returned $data’s were just the html contents of the script’s Success Page so it was easy to just print it to the screen and make sure all was well.  This is what worked for me and hopefully it will help someone else!

3 Comments

  • MingNan Liu says:

    Great!
    I am impressed!
    Thank you very much.
    I’ll try to put the data to IIS site. But I can’t find the that way.
    I had researched many blogs and documents, but all code was not working on IIS site.
    Thank you again.

  • RIchard says:

    Even if it’s just one person a year this helps it’s worth it! Saved me hours of pulling hair!
    Thanks
    Richard

Leave a Reply

Privacy Policy | Refund Policy | Contact

%d bloggers like this: