windows phone 8中如何获取没有return值的JSON数据?
windows phone 8中如何获取没有return值的JSON数据?json数据直接在网页中显示的,比如{"success":"True","code":"1003","msg":"验证码已发送","result":""}
后台是一个没有返回值的webservice,所有数据都必须以POST方式提交,提交给服务器后,服务器并不会给返回值,而是会把运行结果在网页上显示出来,我举个例子:
登录模块中通过sms_verify_code_get_test方法打开这个界面:
(然而并没有上传成功,附地址好了:https://social.msdn.microsoft.com/Forums/getfile/812949)
在输入手机号mobile后点invoke,跳转到的页面是这样的:
(家里电脑真是吃翔了,真的上传不了图片,同样附上链接:https://social.msdn.microsoft.com/Forums/getfile/812951 )
之所以用POST的方式,是因为需要提交一个号码来发送短信验证码,虽然引用服务也可以让服务器给指定的手机号发送验证码,但是获取不到服务器显示的验证码值。但是换用httprequest的方式以stream获取返回数据,却提示not found...我目前完全没头绪了,如果方便的话,可以在这个页面中看一下就知道了:http://222.88.66.22:9100/dongbenservice.asmx?op=sms_verify_code_get_test
最后,附上代码,祈祷大神能看到并给予帮助:
后台是一个没有返回值的webservice,所有数据都必须以POST方式提交,提交给服务器后,服务器并不会给返回值,而是会把运行结果在网页上显示出来,我举个例子:
登录模块中通过sms_verify_code_get_test方法打开这个界面:
(然而并没有上传成功,附地址好了:https://social.msdn.microsoft.com/Forums/getfile/812949)
在输入手机号mobile后点invoke,跳转到的页面是这样的:
(家里电脑真是吃翔了,真的上传不了图片,同样附上链接:https://social.msdn.microsoft.com/Forums/getfile/812951 )
之所以用POST的方式,是因为需要提交一个号码来发送短信验证码,虽然引用服务也可以让服务器给指定的手机号发送验证码,但是获取不到服务器显示的验证码值。但是换用httprequest的方式以stream获取返回数据,却提示not found...我目前完全没头绪了,如果方便的话,可以在这个页面中看一下就知道了:http://222.88.66.22:9100/dongbenservice.asmx?op=sms_verify_code_get_test
最后,附上代码,祈祷大神能看到并给予帮助:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using HttpRequestPostTest.Resources;
using System.IO;
using System.Text;
using System.Runtime.Serialization.Json;
using System.Runtime.Serialization;
namespace HttpRequestPostTest
{
public partial class MainPage : PhoneApplicationPage
{
// 构造函数
public MainPage()
{
InitializeComponent();
// 用于本地化 ApplicationBar 的示例代码
//BuildLocalizedApplicationBar();
}
HttpWebRequest myRequest = null;
private void Button_Click(object sender, RoutedEventArgs e)
{
string url = "http://222.88.66.22:9100/dongbenservice.asmx?op=sms_verify_code_get_test";
myRequest = (HttpWebRequest)WebRequest.Create(new Uri(url));
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;
using (Stream postStream = myRequest.EndGetRequestStream(asynchronousResult))
{
Dictionary<string, string> post = new Dictionary<string, string>();
post.Add("mobile", "18637919897");
byte[] entryBytes = Encoding.UTF8.GetBytes(post.ToString());
postStream.Write(entryBytes, 0, entryBytes.Length);
postStream.Close();
myRequest.BeginGetResponse(new AsyncCallback(GetResponseCallback), request);
}
}
private void GetResponseCallback(IAsyncResult asynchronousResult)
{
HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asynchronousResult);
//这里出现错误:
//“System.Net.WebException”类型的异常在 未知模块。 中发生,但未在用户代码中进行处理
//如有适用于此异常的处理程序,该程序便可安全地继续运行。
Stream streamResponse = response.GetResponseStream();
StreamReader streamRead = new StreamReader(streamResponse);
string responseString = streamRead.ReadToEnd();
this.TextBlock.Text = responseString;
streamRead.Close();
streamResponse.Close();
}
// 用于生成本地化 ApplicationBar 的示例代码
//private void BuildLocalizedApplicationBar()
//{
// // 将页面的 ApplicationBar 设置为 ApplicationBar 的新实例。
// ApplicationBar = new ApplicationBar();
// // 创建新按钮并将文本值设置为 AppResources 中的本地化字符串。
// ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/appbar.add.rest.png", UriKind.Relative));
// appBarButton.Text = AppResources.AppBarButtonText;
// ApplicationBar.Buttons.Add(appBarButton);
// // 使用 AppResources 中的本地化字符串创建新菜单项。
// ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem(AppResources.AppBarMenuItemText);
// ApplicationBar.MenuItems.Add(appBarMenuItem);
//}
}
}
...全文
相关推荐
windows phone8代码
**第20章:数据绑定与MVVM模式** 数据绑定是Windows Phone 8开发中的核心概念,它简化了UI与模型数据的同步。
Windows Phone 8 Application Development Essentials
**Windows Phone 8 平台简介** - Windows Phone 8 是微软发布的一个移动操作系统,是 Windows Phone 7 的后续版本。
Windows Phone 8 Networking Socket 通信 源代码
在Windows Phone 8平台上,网络通信是应用程序与远程服务器或设备交互的重要手段。
windows phone 8.1 入门教程 网络编程 7
### Windows Phone 8.1 入门教程:网络编程篇#### 一、课程简介与讲师介绍在本章节中,我们将深入学习Windows Phone 8.1中的网络编程技术,特别是如何利用`HttpWebRequest
Windows Phone 8 in Action 英文原版 全本
8. **地理位置服务**:讲解如何获取和使用GPS数据,实现地图集成,以及定位服务的应用。9.


