我正在尝试将 c# 中的 json 对象作为参数传递给 mvc 操作,但是当我收到它时,它的值变为 null
有什么建议吗?
var url = "myurl";
var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
httpWebRequest.ContentType = "text/json";
httpWebRequest.Method = "POST";
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
var jsonContent = "{\"addProfileInfo\":{\"Address\" : \"Add Profile\", \"Address2\" : \"add2\", \"ArabicAddress1\" : \"\", \"ArabicAddress2\" : \"\", \"ArabicContactPerson\" : \"\", \"ArabicFirstName\" : \"\", \"ArabicMiddleName\" : \"\", \"ArabicLastName\" : \"\", \"BirthDate\" : \"1998-01-22T00:00:00\", \"CSO\" : 120, \"CompanyActivityId\" : 1, \"ContactPerson\" : \"\", \"Corporate\" : \"No\", \"FaxNumber\" : \"\", \"FirstName\" : \"Add Profile\", \"GeographicalRegionId\" : 58, \"HomeNumber\" : \"0235731789\", \"LastName\" : \"Gamal\", \"LoggedInUserID\" : 1976819, \"MiddleName\" : \"AddProfile\", \"MobileNumber\" : \"01111122829\", \"NationalID\" : null, \"NationalityId\" : 1, \"OccupationId\" : 8, \"OfficeNumber\" : \"\", \"PagerNumber\" : \"0235731739\", \"ParentID\" : 1989567, \"PassportID\" : null, \"Password\" : \"DLDovk65\", \"SendNewsByMail\" : false, \"StateID\" : null, \"StatusID\" : 1, \"StatusReasonID\" : 1, \"TitleId\" : 4, \"UCID\" : \"1007102885\", \"UserAccountManagerID\" : 299489, \"UserComments\" : \"\", \"UserGender\" : 1, \"UserName\" : \"AP.902651\", \"UserPreferredEmail\" : \"AddProfile1@Domain.com\", \"ZipCode\" : \"\"},\"sourceName\":\"LDNCRM\"}";
streamWriter.Write(jsonContent);
}
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var responseText = streamReader.ReadToEnd();
Console.WriteLine(responseText);
}