我正在开发WP8应用程序。我需要使用电子邮件ID和密码在URL中添加数据。我正在使用webclient()
,但我不知道该怎么做。任何人都可以帮我完成任务吗?
提前谢谢。
我的网址格式:
http://xx.xx.xxx.xxx/main/content/api/data/pagename?email=abcd@abcd.com&sig=abcd
这是我的网址结构。我需要为上面的用户添加数据。 我的表单设计:
![enter image description here][1]
当我点击登录按钮时,我应该验证来自上述网址结构的电子邮件和密码。
以下代码适用于发布数据,但我需要知道如何使用电子邮件和密码发布数据。
public T Post<T>(string servicePath, string result)
{
string serviceURL = REST_URI + servicePath;
Uri URI = new Uri(serviceURL);
System.Net.WebClient webClient = new WebClient();
webClient.Headers["ContentType"] = "application/json";
webClient.Headers["Accept"] = "application/json";
webClient.UploadStringCompleted += this.sendPostCompleted;
webClient.UploadStringAsync(URI, HTTP_POST, result);
return default(T);
}
答案 0 :(得分:0)
试试这个,我在这里从文本框中检索用户名和密码,
var username = uname.Text;
var password = pass.Password;
var postData = "email=" + username + "&password=" + password;
WebClient webClient = new WebClient();
webClient.Headers[HttpRequestHeader.ContentType] = "application/json";
var uri = new Uri("Your URL here", UriKind.Absolute);
webClient.Headers[HttpRequestHeader.ContentLength] = postData.Length.ToString();
webClient.AllowWriteStreamBuffering = true;
webClient.Encoding = System.Text.Encoding.UTF8;
webClient.UploadStringAsync(uri, "POST", postData);
webClient.UploadStringCompleted += new UploadStringCompletedEventHandler(postComplete);