如何在WP8中获取get请求? [英] How to do a get request in WP8 ?
本文介绍了如何在WP8中获取get请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好!
我在Windows Phone 8中开始一个项目,我对服务器的连接有点问题..我的GetResponseCallback不起作用,我不知道为什么:/
对不起,如果有人可以帮助我的话,我会抱歉。这将是很好的^^
我把我的代码放在这里。
谢谢你:)) />
public partial class 登录:PhoneApplicationPage
{
public Login()
{
InitializeComponent();
}
private void Login_Click( object sender,RoutedEventArgs e)
{
SendRequest(Box_email.Text,PasswordBox.Password);
}
public void SendRequest( String email, String mdp)
{
// 创建一个新的HttpWebRequest对象。
HttpWebRequest request =(HttpWebRequest)WebRequest.Create( http://19.334.35.55/eip/api/web/app.php/oauth/v2/token?);
string _url = http://19.334.35.55/eip/api/web/app.php/oauth/v2/token跨度>?;
string _email = Username = +电子邮件;
string _mdp = password = + mdp;
request.ContentType = _url + _email + _mdp;
request.Method = GET;
MessageBox.Show( point A debug);
request.BeginGetResponse( new AsyncCallback(GetResponseCallback),request);
allDone.WaitOne();
}
私有 void GetResponseCallback(IAsyncResult) asynchronousResult)
{
// Dispatcher.BeginInvoke(()=>
// {
/ / MessageBox.Show(内部获取响应);
// });
HttpWebRequest request =(HttpWebRequest)asynchronousResult.AsyncState;
if (request!= null )
{
尝试
{
// 结束操作
HttpWebResponse response =(HttpWebResponse)request.EndGetResponse(asynchronousResult);
Stream streamResponse = response.GetResponseStream();
StreamReader streamRead = new StreamReader(streamResponse);
string responseString = streamRead.ReadToEnd();
Console.WriteLine(responseString);
// 关闭流对象
streamResponse.Close();
streamRead.Close();
// 发布HttpWebResponse
response.Close() ;
allDone.Set();
}
catch (WebException e)
{
MessageBox.Show( probleme);
return ;
}
}
}
解决方案
您可以按照本教程进行操作帮助您完成这项任务:
从Windows Phone 8应用程序调用REST服务 [ ^
Hello everyone!
I begin a project in windows phone 8 and i have a little probleme with the connection to server.. my GetResponseCallback doesn't work and i don't know why :/
Sorry for noob question, if somebody can help me. It would be nice ^^
I put my code here.
thank you :)
public partial class Login : PhoneApplicationPage
{
public Login()
{
InitializeComponent();
}
private void Login_Click(object sender, RoutedEventArgs e)
{
SendRequest(Box_email.Text, PasswordBox.Password);
}
public void SendRequest(String email, String mdp)
{
// Create a new HttpWebRequest object.
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://19.334.35.55/eip/api/web/app.php/oauth/v2/token?");
string _url = "http://19.334.35.55/eip/api/web/app.php/oauth/v2/token?";
string _email = "Username=" + email;
string _mdp = "password=" + mdp;
request.ContentType = _url + _email + _mdp;
request.Method = "GET";
MessageBox.Show("point A debug");
request.BeginGetResponse(new AsyncCallback(GetResponseCallback), request);
allDone.WaitOne();
}
private void GetResponseCallback(IAsyncResult asynchronousResult)
{
// Dispatcher.BeginInvoke(() =>
// {
// MessageBox.Show("inside get response");
// });
HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
if (request != null)
{
try
{
// End the operation
HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asynchronousResult);
Stream streamResponse = response.GetResponseStream();
StreamReader streamRead = new StreamReader(streamResponse);
string responseString = streamRead.ReadToEnd();
Console.WriteLine(responseString);
// Close the stream object
streamResponse.Close();
streamRead.Close();
// Release the HttpWebResponse
response.Close();
allDone.Set();
}
catch (WebException e)
{
MessageBox.Show("probleme");
return;
}
}
}
解决方案
You can follow this tutorial which will help you to do this task:
Calling REST Services from a Windows Phone 8 App[^]
这篇关于如何在WP8中获取get请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文