question

tassine avatar image
tassine asked

requesting access token c# , Unable to connect to the remote server

hi everybody, I have some difficulties in requesting an access token. I tried to get it through that : private String getAccessToken(String client_id,String client_secret) { HttpWebRequest httpWReq = (HttpWebRequest)WebRequest.Create(" http://api.amazon.com/auth/02/token"); Encoding encoding = new UTF8Encoding(); string postData = "grant_type=client_credentials"; postData += "&scope=messaging:push"; postData += "&client_id=" + client_id; postData += "&client_secret=" + client_secret; byte[] data = encoding.GetBytes(postData); httpWReq.Method = "POST"; httpWReq.ContentType = "application/x-www-form-urlencoded;charset=UTF-8"; httpWReq.ContentLength = data.Length; using (Stream stream = httpWReq.GetRequestStream()) // ***here I get this exception : Unable to connect to the remote server !!!**** { stream.Write(data, 0, data.Length); } HttpWebResponse response = (HttpWebResponse)httpWReq.GetResponse(); StreamReader reader = new StreamReader(response.GetResponseStream()); String jsonresponse = ""; String temp = null; while ((temp = reader.ReadLine()) != null) { jsonresponse += temp; } var dict = new JavaScriptSerializer().Deserialize >(jsonresponse); access_token = dict["access_token"]; String expires_in = dict["expires_in"]; } return access_token; } I get this execption : Unable to connect to the remote server, when I trie to get request stream !!! someone can help me , please!
amazon device messaging
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

tassine avatar image
tassine answered
url was wrong! I had to put https instead of http in url. https://api.amazon.com/auth/o2/token now it work perfectly. thinks.
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sujoy@Amazon avatar image
Sujoy@Amazon answered
Hi Tassine, Thanks for sharing the code. It would help C# developer to write the server side components for ADM. Thanks.
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.