HttpResponseMessage.Content is in array












-2














Angular call to controller



var objData = {data: JSON.stringify(JSONObject)}
var mapFile = $scope.service.common.WriteDynamicMapFile.save({},
objData).$promise;
mapFile.then(function (response) {**Do Stuff**});


My C# controller



  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;

}
}

}


I'm getting the result back from an WebAPI that looks like



dynamic431d4460-e95d-4d89-a3d8-d452609632d5.map


which is returned on a post



DynamicMapFileName = client.UploadString(theURI, jSonObject);


I bundle the return string up and return it to the calling angular



response = new HttpResponseMessage(HttpStatusCode.OK);
response.Content = new StringContent(DynamicMapFileName);
return response


What I get back in Angular looks like this



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"


How can I just get the string value back in a string format I can use?



Any help is greatly appreciated!!










share|improve this question




















  • 1




    It would be awesome if you could provide a Minimal, Complete, and Verifiable example of the Angular side and the C# side.
    – mjwills
    Nov 15 at 20:25










  • I updated the question
    – Funn_Bobby
    Nov 15 at 21:05










  • @Funn_Bobby could you post the http request and response from angular app ? Seems to me like the response being correct.
    – Nick Polyderopoulos
    Nov 15 at 22:51










  • @NickPolideropoulos Thanks for the response...you're right the data coming back is correct just not in a very usable format...I answered my own question below.
    – Funn_Bobby
    Nov 15 at 22:53
















-2














Angular call to controller



var objData = {data: JSON.stringify(JSONObject)}
var mapFile = $scope.service.common.WriteDynamicMapFile.save({},
objData).$promise;
mapFile.then(function (response) {**Do Stuff**});


My C# controller



  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;

}
}

}


I'm getting the result back from an WebAPI that looks like



dynamic431d4460-e95d-4d89-a3d8-d452609632d5.map


which is returned on a post



DynamicMapFileName = client.UploadString(theURI, jSonObject);


I bundle the return string up and return it to the calling angular



response = new HttpResponseMessage(HttpStatusCode.OK);
response.Content = new StringContent(DynamicMapFileName);
return response


What I get back in Angular looks like this



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"


How can I just get the string value back in a string format I can use?



Any help is greatly appreciated!!










share|improve this question




















  • 1




    It would be awesome if you could provide a Minimal, Complete, and Verifiable example of the Angular side and the C# side.
    – mjwills
    Nov 15 at 20:25










  • I updated the question
    – Funn_Bobby
    Nov 15 at 21:05










  • @Funn_Bobby could you post the http request and response from angular app ? Seems to me like the response being correct.
    – Nick Polyderopoulos
    Nov 15 at 22:51










  • @NickPolideropoulos Thanks for the response...you're right the data coming back is correct just not in a very usable format...I answered my own question below.
    – Funn_Bobby
    Nov 15 at 22:53














-2












-2








-2







Angular call to controller



var objData = {data: JSON.stringify(JSONObject)}
var mapFile = $scope.service.common.WriteDynamicMapFile.save({},
objData).$promise;
mapFile.then(function (response) {**Do Stuff**});


My C# controller



  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;

}
}

}


I'm getting the result back from an WebAPI that looks like



dynamic431d4460-e95d-4d89-a3d8-d452609632d5.map


which is returned on a post



DynamicMapFileName = client.UploadString(theURI, jSonObject);


I bundle the return string up and return it to the calling angular



response = new HttpResponseMessage(HttpStatusCode.OK);
response.Content = new StringContent(DynamicMapFileName);
return response


What I get back in Angular looks like this



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"


How can I just get the string value back in a string format I can use?



Any help is greatly appreciated!!










share|improve this question















Angular call to controller



var objData = {data: JSON.stringify(JSONObject)}
var mapFile = $scope.service.common.WriteDynamicMapFile.save({},
objData).$promise;
mapFile.then(function (response) {**Do Stuff**});


My C# controller



  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;

}
}

}


I'm getting the result back from an WebAPI that looks like



dynamic431d4460-e95d-4d89-a3d8-d452609632d5.map


which is returned on a post



DynamicMapFileName = client.UploadString(theURI, jSonObject);


I bundle the return string up and return it to the calling angular



response = new HttpResponseMessage(HttpStatusCode.OK);
response.Content = new StringContent(DynamicMapFileName);
return response


What I get back in Angular looks like this



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"


How can I just get the string value back in a string format I can use?



Any help is greatly appreciated!!







c# angularjs c#-4.0 httpresponse httpresponsemessage






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 at 21:30

























asked Nov 15 at 20:02









Funn_Bobby

168317




168317








  • 1




    It would be awesome if you could provide a Minimal, Complete, and Verifiable example of the Angular side and the C# side.
    – mjwills
    Nov 15 at 20:25










  • I updated the question
    – Funn_Bobby
    Nov 15 at 21:05










  • @Funn_Bobby could you post the http request and response from angular app ? Seems to me like the response being correct.
    – Nick Polyderopoulos
    Nov 15 at 22:51










  • @NickPolideropoulos Thanks for the response...you're right the data coming back is correct just not in a very usable format...I answered my own question below.
    – Funn_Bobby
    Nov 15 at 22:53














  • 1




    It would be awesome if you could provide a Minimal, Complete, and Verifiable example of the Angular side and the C# side.
    – mjwills
    Nov 15 at 20:25










  • I updated the question
    – Funn_Bobby
    Nov 15 at 21:05










  • @Funn_Bobby could you post the http request and response from angular app ? Seems to me like the response being correct.
    – Nick Polyderopoulos
    Nov 15 at 22:51










  • @NickPolideropoulos Thanks for the response...you're right the data coming back is correct just not in a very usable format...I answered my own question below.
    – Funn_Bobby
    Nov 15 at 22:53








1




1




It would be awesome if you could provide a Minimal, Complete, and Verifiable example of the Angular side and the C# side.
– mjwills
Nov 15 at 20:25




It would be awesome if you could provide a Minimal, Complete, and Verifiable example of the Angular side and the C# side.
– mjwills
Nov 15 at 20:25












I updated the question
– Funn_Bobby
Nov 15 at 21:05




I updated the question
– Funn_Bobby
Nov 15 at 21:05












@Funn_Bobby could you post the http request and response from angular app ? Seems to me like the response being correct.
– Nick Polyderopoulos
Nov 15 at 22:51




@Funn_Bobby could you post the http request and response from angular app ? Seems to me like the response being correct.
– Nick Polyderopoulos
Nov 15 at 22:51












@NickPolideropoulos Thanks for the response...you're right the data coming back is correct just not in a very usable format...I answered my own question below.
– Funn_Bobby
Nov 15 at 22:53




@NickPolideropoulos Thanks for the response...you're right the data coming back is correct just not in a very usable format...I answered my own question below.
– Funn_Bobby
Nov 15 at 22:53












1 Answer
1






active

oldest

votes


















0














So even though this got 2 down votes I think it will be helpful for some...



What I ended up doing was going away from the HttpResponseMessage.
I actually created what I called a "SimpleResponse"



  public class SimpleResponse {
public string data {
get;
set;
}

}


Then I replaced the HttpResponseMessage with the SimpleResponse return type



 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;

}
}

}


Now I get a usable string in my angular.






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53327120%2fhttpresponsemessage-content-is-in-array%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    So even though this got 2 down votes I think it will be helpful for some...



    What I ended up doing was going away from the HttpResponseMessage.
    I actually created what I called a "SimpleResponse"



      public class SimpleResponse {
    public string data {
    get;
    set;
    }

    }


    Then I replaced the HttpResponseMessage with the SimpleResponse return type



     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;

    }
    }

    }


    Now I get a usable string in my angular.






    share|improve this answer


























      0














      So even though this got 2 down votes I think it will be helpful for some...



      What I ended up doing was going away from the HttpResponseMessage.
      I actually created what I called a "SimpleResponse"



        public class SimpleResponse {
      public string data {
      get;
      set;
      }

      }


      Then I replaced the HttpResponseMessage with the SimpleResponse return type



       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;

      }
      }

      }


      Now I get a usable string in my angular.






      share|improve this answer
























        0












        0








        0






        So even though this got 2 down votes I think it will be helpful for some...



        What I ended up doing was going away from the HttpResponseMessage.
        I actually created what I called a "SimpleResponse"



          public class SimpleResponse {
        public string data {
        get;
        set;
        }

        }


        Then I replaced the HttpResponseMessage with the SimpleResponse return type



         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;

        }
        }

        }


        Now I get a usable string in my angular.






        share|improve this answer












        So even though this got 2 down votes I think it will be helpful for some...



        What I ended up doing was going away from the HttpResponseMessage.
        I actually created what I called a "SimpleResponse"



          public class SimpleResponse {
        public string data {
        get;
        set;
        }

        }


        Then I replaced the HttpResponseMessage with the SimpleResponse return type



         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;

        }
        }

        }


        Now I get a usable string in my angular.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 15 at 22:51









        Funn_Bobby

        168317




        168317






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53327120%2fhttpresponsemessage-content-is-in-array%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

            ComboBox Display Member on multiple fields

            Is it possible to collect Nectar points via Trainline?