Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
Amazon AIMS HTTPS POSTDemonstrates a simple post to the Amazon Inventory Management System (AIMS) API using Chilkat HTTP. CREATE PROCEDURE ChilkatSample AS BEGIN DECLARE @hr int DECLARE @sTmp0 nvarchar(4000) DECLARE @req int EXEC @hr = sp_OACreate 'Chilkat.HttpRequest', @req OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END DECLARE @http int EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END DECLARE @success int -- Any string unlocks the component for the 1st 30-days. EXEC sp_OAMethod @http, 'UnlockComponent', @success OUT, 'Anything for 30-day trial' IF @success <> 1 BEGIN EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END -- Before doing the POST, do a simple GET for the purpose of obtaining a Cookie. -- The Cookie contains a session-id and a session-id-time, and these values must -- be current. -- The CookieDir may be set to "memory" to keep an in-memory cache of cookies. -- Alternatively, you may set it to a directory, such as "c:/temp/cookies". If you do that, -- you can visually browse the cookies which will appear as XML files in the CookieDir. EXEC sp_OASetProperty @http, 'CookieDir', 'memory' -- Tell the HTTP component to save any cookies received. Also tell the component to -- re-send cookies with subsequent GETs and POSTs. EXEC sp_OASetProperty @http, 'SendCookies', 1 EXEC sp_OASetProperty @http, 'SaveCookies', 1 -- Do a GET to retrieve our Cookie... DECLARE @html nvarchar(4000) EXEC sp_OAMethod @http, 'QuickGetStr', @html OUT, 'https://secure.amazon.com/exec/panama/seller-admin/manual-reports/get-report-status' -- Build an HTTP POST Request: EXEC sp_OAMethod @req, 'UsePost', NULL EXEC sp_OASetProperty @req, 'Path', '/exec/panama/seller-admin/manual-reports/get-report-status' -- Setting your login/password causes Chilkat to automatically add the Authorization header: EXEC sp_OASetProperty @http, 'Login', 'YourLoginEmailAddress' EXEC sp_OASetProperty @http, 'Password', 'YourPassword' -- NOTE: Do not explicitly add the Cookie header. It is added automatically by Chilkat HTTP. EXEC sp_OAMethod @req, 'AddHeader', NULL, 'Content-Type', 'text/xml' EXEC sp_OAMethod @req, 'AddHeader', NULL, 'NumberofReports', '2' EXEC sp_OAMethod @req, 'AddHeader', NULL, 'ReportName', 'OpenListingsLite' -- Send the HTTP POST and get the response. Note: This is a blocking call. -- The method does not return until the full HTTP response is received. DECLARE @domain nvarchar(4000) DECLARE @port int DECLARE @ssl int SELECT @domain = 'secure.amazon.com' SELECT @port = 443 SELECT @ssl = 1 DECLARE @resp int EXEC sp_OAMethod @http, 'SynchronousRequest', @resp OUT, @domain, @port, @ssl, @req IF @resp Is NULL BEGIN EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 END ELSE BEGIN -- Display the XML returned. EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT PRINT @sTmp0 END END GO |
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2007 Chilkat Software, Inc. All Rights Reserved.