如何从C#Web应用程序中读取shopify数据
问题描述:
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;
}
}
答
无需编写自己的...这是一个积极开发的库您: GitHub - nozzlegear / ShopifySharp:ShopifySharp是一个C#和.NET库,可帮助开发人员轻松验证和管理Shopify商店。 [ ^ ]
No need to write your own... Here is an actively developed library for you: GitHub - nozzlegear/ShopifySharp: ShopifySharp is a C# and .NET library that helps developers easily authenticate with and manage Shopify stores.[^]