Click here to Skip to main content
15,890,609 members
Please Sign up or sign in to vote.
1.33/5 (2 votes)
See more:
I need to write an integration for Shopify. Shopify is an ecommerce platform which lets you create an ecommerce website.
 
So I have to write a c# code which pulls product information from a Shopify store.
 
any example would be appreciated


What I have tried:

public string GetCustomers()
        {
            ServicePointManager.Expect100Continue = true;
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            const string Url = "https://fd49a55f3afafdff141b8ab40809516b:ccb2f6bfa@ausshirts99s34.myshopify.com/admin/orders.json";
            var req = (HttpWebRequest)WebRequest.Create(Url);
            req.Method = "GET";
            req.ContentType = "application/json";
            req.Credentials = GetCredential(Url);
            req.PreAuthenticate = true;
            req.KeepAlive = false;

          //  req.ProtocolVersion = HttpVersion.Version10;
            using (var resp = (HttpWebResponse)req.GetResponse())
            {
                if (resp.StatusCode != HttpStatusCode.OK)
                {
                    string message = String.Format("Call failed. Received HTTP {0}", resp.StatusCode);
                    throw new ApplicationException(message);
                }

                var sr = new StreamReader(resp.GetResponseStream());
                return sr.ReadToEnd();
            }

        }
        private static CredentialCache GetCredential(string url)
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
            var credentialCache = new CredentialCache();
            credentialCache.Add(new Uri(url), "Basic", new NetworkCredential("fd49a55f3afafd8ab40809516b", "ccb2e52e272c0c3f6bfa"));
            return credentialCache;
        }
    }
Posted
Updated 15-Jan-18 3:45am

1 solution

 
Share this answer
 
Comments
Malikdanish 15-Jan-18 9:55am    
this project is not opening in vs 2010/2013
Malikdanish 15-Jan-18 9:56am    
my code gives error on that line " using (var resp = (HttpWebResponse)req.GetResponse())

The request was aborted: Could not create SSL/TLS secure channel
Malikdanish 15-Jan-18 12:47pm    
static void Main(string[] args)
{
// Create a request for the URL.
WebRequest request = WebRequest.Create("https://gdgsdf.myshopify.com/admin/customers.json");
// Set the credentials.
request.Credentials = new NetworkCredential("hhhh", "hhhh");
// Get the response.
HttpWebResponse response = null;
try
{
// This is where the HTTP GET actually occurs.
response = (HttpWebResponse)request.GetResponse();
}
catch (Exception a)
{
Console.WriteLine(a.ToString());
}
// Display the status. You want to see "OK" here.
Console.WriteLine(response.StatusDescription);
// Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream();
// Open the stream using a StreamReader
StreamReader reader = new StreamReader(dataStream);
// Read the content. T
string responseFromServer = reader.ReadToEnd();
// Display the content.
Console.WriteLine(responseFromServer);
// Cleanup the streams and the response.
reader.Close();
dataStream.Close();
response.Close();
}
that solve my issue

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900