我有一个MVC 4 Web api服务层。 我试图使用此代码从我的Web应用程序调用服务层
HttpResponseMessage responsemsg = new HttpResponseMessage();
HttpClient client = new HttpClient();
ServiceUrl = "http://localhost:51093";
client.BaseAddress = new Uri(ServiceUrl);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
ListParams LP = new ListParams();
LP.Add("param1", dtDate.SelectedDate);
LP.Add("Param2", AR.GetMaxAccountRefID().ToNonNullString());
foreach (KeyValuePair<string, object> item in LP)
{
param = param + item.Key + "=" + item.Value + "&";
}
try
{
responsemsg = client.GetAsync("/api/ProductAccount?" + param, HttpCompletionOption.ResponseContentRead).Result;
}
if (responsemsg.IsSuccessStatusCode)
{
// code
}
这很好..如果我正在改变
ServiceUrl ="http://192.168.0.139:8080/"; //(Service Hosted path)
然后它没有调用并获得404错误。
请告诉我哪里缺少任何东西..