HttpResponseMessage.Content 在数组中
HttpResponseMessage.Content is in array
Angular 调用控制器
var objData = {data: JSON.stringify(JSONObject)}
var mapFile = $scope.service.common.WriteDynamicMapFile.save({},
objData).$promise;
mapFile.then(function (response) {**Do Stuff**});
我的 C# 控制器
public class WriteDynamicFileController : ApiController
{
[System.Web.Http.AcceptVerbs("GET", "POST")]
[System.Web.Http.HttpPost]
public HttpResponseMessage POST([FromBody] SimpleRequest data)
{
String DynamicFileName = "";
HttpResponseMessage response = new HttpResponseMessage();
using (HostingEnvironment.Impersonate())
{
try
{
client.Headers.Add("X-Current-User", base.User.GetUsername(true).ToString());
client.Headers[HttpRequestHeader.ContentType] = "application/json";
client.UseDefaultCredentials = true;
DynamicFileName = client.UploadString(theURI, data);
response = new HttpResponseMessage(HttpStatusCode.OK);
response.Content = new StringContent(DynamicFileName);
}
catch (Exception ex)
{
response.ReasonPhrase = ex.InnerException.ToString();
return response
}
return response;
}
}
}
我从 WebAPI 得到的结果看起来像
dynamic1d4460-e95d-4d89-a3d8-d452609632d5.map
return在 post
上编辑
DynamicMapFileName = client.UploadString(theURI, jSonObject);
我将 return 字符串打包并 return 到调用 angular
response = new HttpResponseMessage(HttpStatusCode.OK);
response.Content = new StringContent(DynamicMapFileName);
return response
我在 Angular 中得到的结果看起来像这样
0: "d"
1: "y"
2: "n"
3: "a"
4: "m"
5: "i"
6: "c"
7: "\"
8: "4"
9: "3"
10: "1"
11: "d"
12: "4"
13: "4"
14: "6"
15: "0"
16: "-"
17: "e"
18: "9"
19: "5"
20: "d"
21: "-"
22: "4"
23: "d"
24: "8"
25: "9"
26: "-"
27: "a"
28: "3"
29: "d"
30: "8"
31: "-"
32: "d"
33: "4"
34: "5"
35: "2"
36: "6"
37: "0"
38: "9"
39: "6"
40: "3"
41: "2"
42: "d"
43: "5"
44: "."
45: "m"
46: "a"
47: "p"
我怎样才能以我可以使用的字符串格式取回字符串值?
非常感谢任何帮助!!
所以即使这得到了 2 个反对票,我认为它对某些人会有帮助...
我最终做的是远离 HttpResponseMessage。
我实际上创建了我所谓的 "SimpleResponse"
public class SimpleResponse {
public string data {
get;
set;
}
}
然后我用 SimpleResponse return 类型替换了 HttpResponseMessage
public class WriteDynamicFileController : ApiController
{
[System.Web.Http.AcceptVerbs("GET", "POST")]
[System.Web.Http.HttpPost]
public SimpleResponse POST([FromBody] SimpleRequest data)
{
String DynamicFileName = "";
HttpResponseMessage response = new HttpResponseMessage();
using (HostingEnvironment.Impersonate())
{
try
{
client.Headers.Add("X-Current-User",
base.User.GetUsername(true).ToString());
client.Headers[HttpRequestHeader.ContentType] = "application/json";
client.UseDefaultCredentials = true;
DynamicFileName = client.UploadString(theURI, data);
response.data = DynamicFileName;
}
catch (Exception ex)
{
response.ReasonPhrase = ex.InnerException.ToString();
return response
}
return response;
}
}
}
现在我在 angular 中得到了可用的字符串。
Angular 调用控制器
var objData = {data: JSON.stringify(JSONObject)}
var mapFile = $scope.service.common.WriteDynamicMapFile.save({},
objData).$promise;
mapFile.then(function (response) {**Do Stuff**});
我的 C# 控制器
public class WriteDynamicFileController : ApiController
{
[System.Web.Http.AcceptVerbs("GET", "POST")]
[System.Web.Http.HttpPost]
public HttpResponseMessage POST([FromBody] SimpleRequest data)
{
String DynamicFileName = "";
HttpResponseMessage response = new HttpResponseMessage();
using (HostingEnvironment.Impersonate())
{
try
{
client.Headers.Add("X-Current-User", base.User.GetUsername(true).ToString());
client.Headers[HttpRequestHeader.ContentType] = "application/json";
client.UseDefaultCredentials = true;
DynamicFileName = client.UploadString(theURI, data);
response = new HttpResponseMessage(HttpStatusCode.OK);
response.Content = new StringContent(DynamicFileName);
}
catch (Exception ex)
{
response.ReasonPhrase = ex.InnerException.ToString();
return response
}
return response;
}
}
}
我从 WebAPI 得到的结果看起来像
dynamic1d4460-e95d-4d89-a3d8-d452609632d5.map
return在 post
上编辑DynamicMapFileName = client.UploadString(theURI, jSonObject);
我将 return 字符串打包并 return 到调用 angular
response = new HttpResponseMessage(HttpStatusCode.OK);
response.Content = new StringContent(DynamicMapFileName);
return response
我在 Angular 中得到的结果看起来像这样
0: "d"
1: "y"
2: "n"
3: "a"
4: "m"
5: "i"
6: "c"
7: "\"
8: "4"
9: "3"
10: "1"
11: "d"
12: "4"
13: "4"
14: "6"
15: "0"
16: "-"
17: "e"
18: "9"
19: "5"
20: "d"
21: "-"
22: "4"
23: "d"
24: "8"
25: "9"
26: "-"
27: "a"
28: "3"
29: "d"
30: "8"
31: "-"
32: "d"
33: "4"
34: "5"
35: "2"
36: "6"
37: "0"
38: "9"
39: "6"
40: "3"
41: "2"
42: "d"
43: "5"
44: "."
45: "m"
46: "a"
47: "p"
我怎样才能以我可以使用的字符串格式取回字符串值?
非常感谢任何帮助!!
所以即使这得到了 2 个反对票,我认为它对某些人会有帮助...
我最终做的是远离 HttpResponseMessage。 我实际上创建了我所谓的 "SimpleResponse"
public class SimpleResponse {
public string data {
get;
set;
}
}
然后我用 SimpleResponse return 类型替换了 HttpResponseMessage
public class WriteDynamicFileController : ApiController
{
[System.Web.Http.AcceptVerbs("GET", "POST")]
[System.Web.Http.HttpPost]
public SimpleResponse POST([FromBody] SimpleRequest data)
{
String DynamicFileName = "";
HttpResponseMessage response = new HttpResponseMessage();
using (HostingEnvironment.Impersonate())
{
try
{
client.Headers.Add("X-Current-User",
base.User.GetUsername(true).ToString());
client.Headers[HttpRequestHeader.ContentType] = "application/json";
client.UseDefaultCredentials = true;
DynamicFileName = client.UploadString(theURI, data);
response.data = DynamicFileName;
}
catch (Exception ex)
{
response.ReasonPhrase = ex.InnerException.ToString();
return response
}
return response;
}
}
}
现在我在 angular 中得到了可用的字符串。