我是silverlight的新手。我在Visual Studio 2010中爲Windows phone編程。 我嘗試做HttpWebRequest但調試器說ProtocolViolationException。 這是我的代碼當我做BeginGetRequestStream時爲什麼會得到ProtocolViolationException
private void log_Click(object sender, RoutedEventArgs e)
{
//auth thi is my url for request
string auth;
string login = Uri.EscapeUriString(this.login.Text);
string password = Uri.EscapeUriString(this.pass.Password);
auth = "https://api.vk.com/oauth/token";
auth += "?grant_type=password" + "&client_id=*****&client_secret=******&username=" + login + "&password=" + password + "&scope=notify,friends,messages";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(auth);
request.BeginGetRequestStream(RequestCallBack, request);//on this line debager say ProtocolViolationExceptio
}
void RequestCallBack(IAsyncResult result)
{
HttpWebRequest request = result.AsyncState as HttpWebRequest;
Stream stream = request.EndGetRequestStream(result);
request.BeginGetResponse(ResponceCallBack, request);
}
void ResponceCallBack(IAsyncResult result)
{
HttpWebRequest request = result.AsyncState as HttpWebRequest;
HttpWebResponse response = request.EndGetResponse(result) as HttpWebResponse;
using (StreamReader sr = new StreamReader(response.GetResponseStream()))
{
string a =sr.ReadToEnd();
MessageBox.Show(a);
}
}
你忘了清理一個客戶機祕密/ ID對 – Dani 2012-08-14 15:19:05
有人可以給我工作代碼的HttpWebRequest? – user1597524 2012-08-14 15:35:15