我有一个控制台应用程序,我用它来调用我的 MVC WebApi 控制器的 CRUD 操作。
目前我的 HTTP 请求设置如下:
string _URL = "http://localhost:1035/api/values/getselectedperson";
var CreatePersonID = new PersonID
{
PersonsID = ID
};
string convertedJSONPayload = JsonConvert.SerializeObject(CreatePersonID, new IsoDateTimeConverter());
var httpWebRequest = (HttpWebRequest)WebRequest.Create(_URL);
httpWebRequest.Headers.Add("Culture", "en-US");
httpWebRequest.ContentType = "application/json";
httpWebRequest.Accept = "application/json";
httpWebRequest.Method = "GET";
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
streamWriter.Write(convertedJSONPayload);
streamWriter.Flush();
streamWriter.Close();
}
return HandleResponse((HttpWebResponse)httpWebRequest.GetResponse());
如何将 JSON ID 参数添加到 URL 并由我的控制器“GetSelectPerson”接收?
public IPerson GetSelectedPerson(object id)
{
....... code
}