System.Net.HttpWebRequest.GetResponse returns 401

1,687 views
Skip to first unread message

Michael G.

unread,
Jul 18, 2011, 11:01:39 AM7/18/11
to shopify-api
I created a new private app, copied the example URL that got created,
and pasted it into the following C# code:


WebRequest request = WebRequest.Create("http://
7281...myshopify.com/admin/orders.xml");
HttpWebResponse response =
(HttpWebResponse)request.GetResponse();

I get:

System.Net.WebException was unhandled
Message=The remote server returned an error: (401) Unauthorized.

I tried various combinations of request.UseDefaultCredentials,
request.PreAuthenticate, and request.AuthenticationLevel. I also
tried https instead of http.

Has anyone successfully called the API from a .NET desktop
application?

Thanks!

John Duff

unread,
Jul 18, 2011, 11:41:19 AM7/18/11
to shopi...@googlegroups.com
I think your issue could be that the url is http instead of https.
There is an error on api page where we show the url as http, but it
needs to be https, we're going to fix that right away.

John Duff
Developer @ Shopify

Michael G.

unread,
Jul 18, 2011, 3:26:10 PM7/18/11
to shopify-api
Thanks, John, but I already tried both http and https. Same
exception.

John Duff

unread,
Jul 18, 2011, 5:19:55 PM7/18/11
to shopify-api
I'll see if I can try this out tonight, but one other thing to try
would be to specify the basic auth credentials? Something like this
maybe?

WebRequest request = WebRequest.Create("https://shop.myshopify.com/
admin/orders.xml");

request.Credentials = new NetworkCredential("apikey", "password");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();

I know that there is at least one other person doing some windows
development with the shopify api, maybe they could chime in?

Michael G.

unread,
Jul 19, 2011, 8:12:56 AM7/19/11
to shopi...@googlegroups.com
Yes, that did the trick!   When setting the the credentials directly, the request succeeds with either http or https.  Many thanks.
Reply all
Reply to author
Forward
0 new messages