Windows phone 7 访问带有更改URL的变量的URL,即windows phone
我有一个URL,如下所示: 由于合同原因,URL被删除Windows phone 7 访问带有更改URL的变量的URL,即windows phone,windows-phone-7,windows-phone,Windows Phone 7,Windows Phone,我有一个URL,如下所示: 由于合同原因,URL被删除 WebClient webClient = new WebClient(); Uri uri = new Uri("http://www.URLhere.aspx?stopid=4556"); webClient.OpenReadCompleted += new OpenReadCompletedEventHandler (webClient_O
WebClient webClient = new WebClient();
Uri uri = new Uri("http://www.URLhere.aspx?stopid=4556");
webClient.OpenReadCompleted += new OpenReadCompletedEventHandler
(webClient_OpenReadCompleted);
webClient.OpenReadAsync(uri);
我需要找到一种方法来改变结束部分,将4556从一个文本块更改为另一个文本,这样当应用程序发送请求时,它可以找到整个部分
我以为你能做到:
WebClient webClient = new WebClient();
Uri uri = new Uri("http://www.URLhere.aspx?stopid=" + stopId);
webClient.OpenReadCompleted += new OpenReadCompletedEventHandler
(webClient_OpenReadCompleted);
webClient.OpenReadAsync(uri);
如何做到这一点
编辑:
当我执行上面的代码时,它返回一个空引用,因此我认为它没有得到文本框中的文本 两者之间没有区别
Uri uri = new Uri("http://www.URLhere.aspx?stopid=4556");
及
所以我真的不知道你的问题是什么听起来你缺少变量的编码
var myvar = "the simpsons";
Uri myUri = new Uri("http://www.URLhere.aspx?stopid=" + HttpUtility.UrlEncode(myvar));
见亨利,
如果我正确理解您的问题,我认为您希望将文本框(而不是文本块)中的值附加到URI。如果这是正确的,并且您使用的是MVVM,那么您可以将TextBox绑定到ViewModel上的公共属性(我们称之为TextBoxProp)
然后按如下方式创建URI:
Uri uri = new Uri(String.Format("http://www.URLhere.aspx?stopid={0}", TextBoxProp));
当绑定到XAML中的属性时,请确保将模式设置为双向。
我希望这能有所帮助我真的不明白你的问题是什么。谢谢,我稍微改进了它,将值更改为用户输入的值。但是谢谢你帮我到了那里。你怎么做到的?service.aspx?routes=true&timetables=true&maps=true&serviceid=1149&xsl=json我需要更改serviceid是否与上面的解决方案相同,但最后添加了这个?抱歉,什么?只需创建您的字符串,即URL。任何非硬编码的内容(即变量),请在连接字符串之前使用HttpUtility.UrlEncode。
private string _textBoxProp;
public string TextBoxProp
{
get{return _textBoxProp;}
set
{
_textBoxProp = value;
RaisePropertyChanged("TextBoxProp");
}
}
Uri uri = new Uri(String.Format("http://www.URLhere.aspx?stopid={0}", TextBoxProp));