How do i post data in json? As I keep receiving the error message that I have not passed the parameter. This is my c# code:
Firing the button: url = szAPIURL + url;
WebClient postWithParamsClient = new WebClient();
postWithParamsClient.UploadStringCompleted +=
new UploadStringCompletedEventHandler(postWithParamsClient_UploadStringCompleted);
postWithParamsClient.Headers["Content-Length"] = postdata.Length.ToString();
postWithParamsClient.UploadStringAsync(new Uri(url),
"POST",
"?username=name123&password=pass123");
private void postWithParamsClient_UploadStringCompleted(object sender,
UploadStringCompletedEventArgs e)
{
if (e.Error == null)
MessageBox.Show("WebClient: " + e.Result);
else
MessageBox.Show("WebClient: " + e.Error.Message);
}
This is what I receive from the call :
[{"error_code":2,"error_messages":["You must specify login user name and password"],"tokenid":"","userid":0}]
This is the original ajax api:
var msgData = {};
msgData['username'] = szUserName;
msgData['password'] = szEncryptedPassword;
$.ajax({
url: szAPIURL + "Authenticate",
type: 'POST',
// data need to post tp the server.
//data: JSON.stringify({data:"test"}),
data: msgData,
/*dataType: "jsonp",*/
dataType: "json",