Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
integration:foxycart:datafeed_with_csharp [2012/08/15 10:05] – [Requirements] 95.144.180.128integration:foxycart:datafeed_with_csharp [2015/10/29 17:04] – [Code] foxyluke
Line 6: Line 6:
 name          : ASP.NET C\# API + Datafeed Code                 # the name of the integration name          : ASP.NET C\# API + Datafeed Code                 # the name of the integration
 description   : Functions to interact with the FoxyCart API and XML Datafeed                 description   : Functions to interact with the FoxyCart API and XML Datafeed                
-tags_tags     : api, datafeed, xml, c\#, csharp, integration                # tags, separated by commas. don't include the "system" here.+tags          : api, datafeed, xml, c\#, csharp, integration                # tags, separated by commas. don't include the "system" here.
 date_dt       : 2011-06-01                # the date in YYYY-MM-DD format date_dt       : 2011-06-01                # the date in YYYY-MM-DD format
 version       : 1.0                # if you have a version for your code, enter it here version       : 1.0                # if you have a version for your code, enter it here
Line 13: Line 13:
  
  
-====== ASP.NET with C\# XML Datafeed E-Commerce Integration ======+====== ASP.NET with C# XML Datafeed E-Commerce Integration ======
  
 <WRAP important round> <WRAP important round>
Line 49: Line 49:
         try         try
         {         {
-            string foxyFeed = Request.Form["FoxyData"]; +            var foxyFeed = Request.Form["FoxyData"]; 
-            byte[] ffBytes = Encoding.ASCII.GetBytes(foxyFeed); +            //Changed from ASCII to UTF8. Not sure why you'd get ASCII bytes on UTF-8 encoded data 
-            string unencodedFeed = HttpUtility.UrlDecode(ffBytes, Encoding.GetEncoding(1252)); +            var ffBytes = Encoding.UTF8.GetBytes(foxyFeed); 
-            string transaction = RC4.Decrypt(API_KEY, unencodedFeed, false); +            //This takes the UTF-8 encoded bytes and decodes them to Latin-1. If the decoded data is not Latin-1, the RC4.Decrypt, doesn't seem to function properly. 
- +            var unencodedFeed = HttpUtility.UrlDecode(ffBytes, Encoding.GetEncoding(1252));      
-            //Process the XML string "transaction" as desired. +            var decryptedTransaction = RC4.Decrypt(API_KEY, unecodedUTF8Feed, false); 
 +            //At this point, we've decrypted UTF-8 data using the Latin-1 encoding, which functions properly, unless there are special characters in your data.  
 +            //http://www.weblogism.com/item/270/why-does-e-become-a 
 +            //In order to fix the special characters, you need to turn the string back into Latin-1 bytes, and convert it to a UTF-8 string.  
 +            var transaction = Encoding.UTF8.GetString(Encoding.GetEncoding(1252).GetBytes(decryptedTransaction)); 
 +                         
 +            //Now you can process the XML string "transaction" as desired. 
 +     
             Response.Write("foxy");             Response.Write("foxy");
         }         }
         catch (Exception) { }   //Just eat all exceptions.  You can log this internally if you'd like.         catch (Exception) { }   //Just eat all exceptions.  You can log this internally if you'd like.
     }     }
- 
  
     /**     /**

Site Tools