Domanda

I want to get a list of my sent Messages using a GET, when I put the url (which includes credentials) in my browser I receive the XML but putting the same url in my code and creating a HttpResponse there throws a 401 Authentication error:

        string accountSid = "mysid";
        string authToken = "mytoken";
        string url = "https://mysid:mytoken@api.twilio.com/2010-04-01/Accounts/mysid/SMS/Messages/";
        var twilio = new TwilioRestClient(accountSid, authToken);
        var message = twilio.SendSmsMessage("from number","to number","test","");
        HttpWebRequest http = (HttpWebRequest)WebRequest.Create(url);
        http.Method = "GET";
        HttpWebResponse resp = (HttpWebResponse) http.GetResponse();
        StreamReader streamIn = new StreamReader(resp.GetResponseStream());
        string res = streamIn.ReadToEnd();
        streamIn.Close();
        Console.WriteLine(res + " status ");

Any ideas?

È stato utile?

Soluzione

I'm not well versed in C#, but you may want to remove the credentials from your url and include them as described here: http://msdn.microsoft.com/en-us/library/system.net.networkcredential%28v=vs.110%29.aspx

For example:

WebRequest request = WebRequest.Create("http://www.contoso.com/");
request.Credentials = CredentialCache.DefaultCredentials;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top