如何在 json 中发布数据?当我不断收到我没有传递参数的错误消息时。这是我的 C# 代码:
触发按钮: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);
}
这是我从电话中收到的:
[{"error_code":2,"error_messages":["You must specify login user name and password"],"tokenid":"","userid":0}]
这是原始的ajax api:
var msgData = {};
msgData['username'] = szUserName;
msgData['password'] = szEncryptedPassword;
$.ajax({
url: szAPIURL + "Authenticate",
type: 'POST',
// 数据需要发送到服务器。
//data: JSON.stringify({data:"test"}),
data: msgData,
/*dataType: "jsonp",*/
dataType: "json",