2015-05-04 34 views
0

任何人都知道如何通過使用HTTPWebrequest像web客戶端傳遞參數post方法如下所示請幫助我......如何傳遞參數如用戶名和密碼在Windows Phone 8使用http

WebClient sharegroupclient = new WebClient(); 
Uri uristring = null; 
uristring = new Uri(uri); 
sharegroupclient.Headers["Content-Type"] = "application/x-www-form-urlencoded"; 
sharegroupclient.Credentials = _groupaccount.GetCredentials(); 

string JsonStringParams = "group_admin=" + _groupaccount.Username + "&search=" + searchtext.Text + "&action=" + "search_group"; 
sharegroupclient.UploadStringCompleted += wc_RemoveUserGroupStringCompleted; 
sharegroupclient.UploadStringAsync(uristring, "POST", JsonStringParams); 

回答

0

但是,如果您可以使用HttpClient,您爲什麼要使用WebClient。要使用HttpClient,您只需從Microsoft自身添加this lib即可。

代碼HttpClient

 HttpClient objClient = new HttpClient(); 
     MultipartFormDataContent form = new MultipartFormDataContent(); 
     form.Add(new StringContent("password text"), "Password key"); 
     form.Add(new StringContent("userID text"), "userID key"); 

     var response = await objClient.PostAsync(new Uri("URI string", UriKind.Absolute), form); 

希望幫助.. !!

相關問題