windows phone 7 通过Post提交URL到服务器,从服务器获取数据(比如登陆时候使用)
2014-03-05 00:17
716 查看
原文:windows phone 7 通过Post提交URL到服务器,从服务器获取数据(比如登陆时候使用)
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(UrlManager.Login()); myRequest.Method = "POST"; myRequest.ContentType = "application/x-www-form-urlencoded"; myRequest.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback), myRequest); private void GetRequestStreamCallback(IAsyncResult asynchronousResult) { HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState; System.IO.Stream postStream = request.EndGetRequestStream(asynchronousResult); // Prepare Parameters String string parametersString = "username=用户名&password=密码"; //foreach (KeyValuePair<string, string> parameter in parameters) //{ // parametersString = parametersString + (parametersString != "" ? "&" : "") + string.Format("{0}={1}", parameter.Key, parameter.Value); //} byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(parametersString); // Write to the request stream. postStream.Write(byteArray, 0, parametersString.Length); postStream.Close(); // Start the asynchronous operation to get the response request.BeginGetResponse(new AsyncCallback(GetResponseCallback), request); } private void GetResponseCallback(IAsyncResult asynchronousResult) { HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState; HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asynchronousResult); Stream streamResponse = response.GetResponseStream(); StreamReader streamRead = new StreamReader(streamResponse); string responseString = streamRead.ReadToEnd(); // Close the stream object streamResponse.Close(); streamRead.Close(); }
相关文章推荐
- windows phone 7 通过Post提交URL到服务器,从服务器获取数据(比如登陆时候使用)
- HttpURLconnection使用POST方式提交JSON数据给服务器
- 使用HttpURLConnection通过POST方式提交请求数据,并上传文件
- HttpURLconnection使用POST方式提交JSON数据给服务器
- post提交的数据有哪几种编码格式?能否通过URL参数获取用户账户密码
- 程序使用 HTTP 协议和服务器交互主要是进行数据的提交,通常数据的提交是通过 GET 和 POST 两种方式来完成
- 获取客户端ip地址方法和通过curl在命令行提交post数据到服务器
- C++使用POST方法向网页提交数据-----C++发送HTTP数据获取Google天气预报
- post表单提交后,后台获取数据为null 大量数据的时候会出现这个问题
- Android之使用HTTP协议的Get/Post方式向服务器提交数据
- Java 通过HttpURLConnection Post方式提交json,并从服务端返回json数据
- 使用GET和POST方式将数据提交给服务器
- Android 通过Get/Post提交请求数据到服务器
- 使用Post方式提交数据到Tomcat服务器的方法
- android开发案例之使用JSON数据向服务器提交和获取服务器传递的Json数据
- Android-使用GET、POST、AsyncHttpClient向服务器提交数据
- Java 通过HttpURLConnection Post方式提交json,并从服务端返回json数据
- 使用get,post,httpclient三种方式向服务器提交文本数据
- Android之使用HttpPost提交数据到服务器(Android手机客户端和后台服务器交互)
- 使用HttpURLConnection通过post请求服务器时,URLEncode编码的必要性