user3737951
user3737951

Reputation: 11

How to pass the parameters like username and password in windows phone 8 using http

Any one knew how to pass the parameters to post method using HTTPWebrequest like web client as shown below.Please help me......

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); 

Upvotes: 1

Views: 187

Answers (1)

Keval Langalia
Keval Langalia

Reputation: 1892

but why would you like to use WebClient when you can use HttpClient. To use HttpClient you just need to add this lib from Microsoft itself.

Code for 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);

Hope that helps..!!

Upvotes: 1

Related Questions