我想将身份验证详细信息发布到远程服务器,发送用户名,数据库名称和密码。我的服务器在Ubuntu上运行。但我得到错误无效的JSON数据:'' “POST / HTTP / 1.1”400 - 我是新手,在这个平台上工作,帮助我做错了。以下是我的代码:
private void SendDataButton_Click(object sender, RoutedEventArgs e)
{
string url = "http://200.84.100.211:9875";
string call = url + "/web/session/authenticate";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(call) as HttpWebRequest;
request.ContentType = "application/json";
request.Method = "POST";
request.BeginGetResponse(new AsyncCallback(SendData), request);
}
void SendData(IAsyncResult callbackResult)
{
HttpWebRequest myRequest = (HttpWebRequest)callbackResult.AsyncState;
Stream postStream = myRequest.EndGetRequestStream(callbackResult);
string postData = "{'db':'demo_shruti','login':'admin','password':'admin'}";
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
postStream.Write(byteArray, 0, byteArray.Length);
postStream.Close();
myRequest.BeginGetResponse(new AsyncCallback(FinishWebRequest), myRequest);
}
void FinishWebRequest(IAsyncResult callbackResult)
{
HttpWebRequest request = (HttpWebRequest)callbackResult.AsyncState;
HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(callbackResult);
string responseString = "";
Stream streamResponse = response.GetResponseStream();
StreamReader reader = new StreamReader(streamResponse);
responseString = reader.ReadToEnd();
streamResponse.Close();
reader.Close();
response.Close();
string result = responseString;
}