2014-04-10 55 views
2

我试图连接到VB.NET中的Shopify API并下载一些json订单信息,但每次尝试时我都会收到“401未经授权的访问”错误。我使用达到此目的的代码如下:401在VB.Net中使用Shopify API的未授权访问错误

'Develop API string to get orders 
    Dim url As String 
    url = "https://" & apikey & ":" & apipassword & "@" & domain & "/admin/orders.json" 

    'Create new web service connection 
    Dim ws As New WebClient() 

    'Get json data from remote Shopify server 
    Dim json_data As String 
    Try 
     json_data = ws.DownloadString(url) 
    Catch ex As Exception 
     MsgBox("Connection to the remote server failed! Please check your internet connection or contact the developer.", vbOKOnly, "Connection Failed") 
     Exit Sub 
    End Try 

我知道有授权的另一个水平Shopify用途(OAuth的),但我不知道如何实现这一点。如果有人能够提供帮助,我们将非常感谢。

+0

我无法找到的shopify URL调用这样的例子。你有没有考虑过使用他们的[.NET API](http://docs.shopify.com/api/libraries/net) – PsychoData

回答

1

尝试:

Dim request As WebRequest = WebRequest.Create("https://shop.myshopify.com/admin/orders.json") 

request.Credentials = New NetworkCredential("apikey", "password") 
Dim response As HttpWebResponse = DirectCast(request.GetResponse(), HttpWebResponse) 
相关问题