2013-02-07 54 views
1

我曾嘗試這個代碼從他們的網站利用發送短信的Clickate在ASP.Net

using System.Net; 
using System.IO; 
WebClient client = new WebClient(); 
// Add a user agent header in case the requested URI contains a query. 
client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)"); 
client.QueryString.Add("user", "xxxx"); 
client.QueryString.Add("password", "xxxx"); 
client.QueryString.Add("api_id", "xxxx"); 
client.QueryString.Add("to", "xxxx"); 
client.QueryString.Add("text", "This is an example message"); 
string baseurl = "http://api.clickatell.com/http/sendmsg"; 
Stream data = client.OpenRead(baseurl); 
StreamReader reader = new StreamReader(data); 
string s = reader.ReadToEnd(); 
data.Close(); 
reader.Close(); 
return s; 

我得到的

string baseurl ="http://api.clickatell.com/http/sendmsg"; 

的代理身份驗證失敗誰能幫助我?

+0

什麼是失敗消息? – Aristos

+0

錯誤消息是:遠程服務器返回錯誤:(407)需要代理驗證。 – HelloASP

回答

0

我想你是在一個代理的背後,你的網絡客戶端需要進行身份驗證。請嘗試以下代碼:

string userName = "<user name>"; 
string password = "<password>"; 
ICredentials creds = new NetworkCredential(userName, password); 
client.Credentials = creds; 
+0

仍然是同樣的錯誤。 – HelloASP