none
Client.PostAsync(Uri,content) throws 500 internal server error RRS feed

  • Question

  • I have checked this. Any way to get the values?. I tried to retrieve the data from XML.

     using (HttpClient cl = new HttpClient())

                {
                    cl.BaseAddress = new Uri("provided url");
                    cl.DefaultRequestHeaders.Accept.Clear();
                    cl.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
                    string str = @"{ ""title"":""Sharepoint migration"",""type"":""page"",""space"": {""key"":""ME"" } ""body"":{""storage"":{""value"":""<p>New page data.</p>"",""representation"":""storage""}}}";

                    var credentials = Encoding.ASCII.GetBytes("username:pwd");
                    cl.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(credentials));
                    
                    var content = new StringContent(str, Encoding.UTF8, "application/json");
                   
                   var responseMessage =  await System.Threading.Tasks.Task.Run(()=> cl.PostAsync(@"/rest/api/content", content));
                   
                  
                }




    Wednesday, October 11, 2017 7:59 AM

All replies

  • This is insufficient information. What type is Client? Please post the full code.

    Michael Taylor http://www.michaeltaylorp3.net

    Wednesday, October 11, 2017 2:15 PM
    Moderator
  • Hi,

    Thank you for posting here.

    I think that you might find the server doesn't like that.   Try to find out what media type the server is expecting and set theHeaders.ContentTypeof the StringContentinstance.

    The following links provide a similar solution.

    Send httpcontent with PostAsync gives Internal Server Error

    Best Regards,

    Hart


    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, October 12, 2017 7:07 AM