2011-10-11 55 views
0

我的代碼是:401擅自城市飛艇錯誤的Android

String encodedData = Base64.encodeBytes("YxxxxxxxxxxxxxxxA".getBytes()); 

HttpParams httpParams = new BasicHttpParams(); 
       HttpConnectionParams.setConnectionTimeout(httpParams, TIMEOUT_MILLISEC); 
       HttpConnectionParams.setSoTimeout(httpParams, TIMEOUT_MILLISEC); 
       HttpClient client = new DefaultHttpClient(httpParams); 

       HttpPost request = new HttpPost("https://go.urbanairship.com/api/airmail/send/broadcast/"); 
       //request.setHeader(header) 
       request.addHeader("Authorization", "Basic " + encodedData) 

正在使用的應用程序的主祕密按照該文件建議在這裏:

http://urbanairship.com/docs/richpush.html?highlight=broadcast

但我得到401未經授權錯誤。

如何解決這個問題?

謝謝

回答

1

401錯誤表示您沒有正確驗證。看到這個:http://en.wikipedia.org/wiki/List_of_HTTP_status_codes#4xx_Client_Error

你確定你正在提供你的憑據嗎?

+0

是的主祕密是通過,我檢查它的正確,但是這種身份驗證的方式.. – Udaykiran

+0

呃,這是2016年,我現在有這個問題。沒有人似乎有答案:http://stackoverflow.com/questions/35664399/how-come-i-keep-getting-a-request-failed-with-response-code-401-when-trying-to – Silverstar