Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8430317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:34:26+00:00 2026-06-10T05:34:26+00:00

I’m trying to make a post to my web api service. The point is

  • 0

I’m trying to make a post to my web api service. The point is that while sending a message like

{ message: "it is done" }

working fine. However when I use special characters like çıöpş in my message it is unable to convert my json so that the post object remains null. What can I do? It is either current culture issue or something else. I tried to send my post parameter as HtmlEncoded style with encoding HttpUtility class but it didn’t work either.

public class Animal{

  public string Message {get;set;}
}

Web API method

public void DoSomething(Animal a){

}

Client

Animal a = new Animal();
a.Message = "öçşistltl";
string postDataString = JsonConvert.SerializeObject(a);        
string URL = "http://localhost/Values/DoSomething";
WebClient client = new WebClient();

client.UploadStringCompleted += client_UploadStringCompleted;
client.Headers["Content-Type"] = "application/json;charset=utf-8";
client.UploadStringAsync(new Uri(URL), "POST",postDataString);

Best regards,

Kemal

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T05:34:27+00:00Added an answer on June 10, 2026 at 5:34 am

    One possibility is to use the UploadDataAsync method which allows you to specify UTF-8 when encoding the data because the UploadStringAsync method that you are using basically uses Encoding.Default to encode the data when writing it to the socket. So if your system is configured to use some other encoding than UTF-8 you get into trouble because UploadStringAsync uses your system encoding whereas in your content type header you have specified charset=utf-8 which could be conflicting.

    With the UploadDataAsync method you could be more explicit in your intents:

    Animal a = new Animal();
    a.Message = "öçşistltl";
    string postDataString = JsonConvert.SerializeObject(a);        
    string URL = "http://localhost/Values/DoSomething";
    string postDataString = JsonConvert.SerializeObject(a);
    using (WebClient client = new WebClient())
    {
        client.UploadDataCompleted += client_UploadDataCompleted;
        client.Headers["Content-Type"] = "application/json; charset=utf-8";
        client.UploadDataAsync(new Uri(URI), "POST", Encoding.UTF8.GetBytes(postDataString));
    }
    

    Another possibility is to specify the encoding of the client and use UploadStringAsync:

    Animal a = new Animal();
    a.Message = "öçşistltl";
    string postDataString = JsonConvert.SerializeObject(a);        
    string URL = "http://localhost/Values/DoSomething";
    string postDataString = JsonConvert.SerializeObject(a);
    using (WebClient client = new WebClient())
    {
        client.Encoding = Encoding.UTF8;
        client.UploadStringCompleted += client_UploadStringCompleted;
        client.Headers["Content-Type"] = "application/json; charset=utf-8";
        client.UploadStringAsync(new Uri(URI), "POST", postDataString);
    }
    

    Or if you install the Microsoft.AspNet.WebApi.Client NuGet package on the client you could directly use the new HttpClient class (which is the new kid on the block) to consume your WebAPI instead of WebClient:

    Animal a = new Animal();
    a.Message = "öçşistltl";
    var URI = "http://localhost/Values/DoSomething";
    using (var client = new HttpClient())
    {
        client
            .PostAsync<Animal>(URI, a, new JsonMediaTypeFormatter())
            .ContinueWith(x => x.Result.Content.ReadAsStringAsync().ContinueWith(y =>
            {
                Console.WriteLine(y.Result);
            }))
            .Wait();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.