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

  • SEARCH
  • Home
  • 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 8223911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:52:48+00:00 2026-06-07T14:52:48+00:00

i am facing a problem where i try to communicate with a Ruby API

  • 0

i am facing a problem where i try to communicate with a Ruby API from a C# application.

I need to POST some JSON data, with the parameter name “data” but the API return me: ‘!! Unexpected error while processing request: invalid %-encoding’.

I tried with Content-Type set to ‘application/json’ and ‘application/x-www-form-urlencoded; charset=utf-8’.

My POST data look like this ‘data=some_json_string’.

I figure i should escape the json string, so if it is my problem, how to do it with .NET without using a 3rd party library?

Code:

        byte[] data = System.Text.ASCIIEncoding.UTF8.GetBytes(sdata);

        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(url, UriKind.Absolute));

        request.Method = "POST";
        request.ContentType = "application/x-www-form-urlencoded; charset=utf-8";
        request.ContentLength = data.Length;

        Stream reqStream = request.GetRequestStream();

        // Send the data.
        reqStream.Write(data, 0, data.Length);
        reqStream.Close();

Thanks in advance!

  • 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-07T14:52:49+00:00Added an answer on June 7, 2026 at 2:52 pm

    Presuming the string sdata coming in is already in JSON format you could do:

    using (WebClient wc = new WebClient())
    {
        string uri = "http://www.somewhere.com/somemethod";
        string parameters = "data=" + Uri.EscapeDataString(sdata);
        wc.Headers["Content-type"] = "application/x-www-form-urlencoded";
        string result = wc.UploadString(uri, parameters);
    }
    

    Depending on the consuming service it may need the Content-type set to application/json?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok, facing the problem I can't parse my data from inside the try{} to
Im currently facing the problem that when i try to set focus on some
I have facing problem in listview i am getting data from server and after
I am facing a problem in my application. I have some section in application
I m facing big problem With Application Termination State.In My app need to Satisfied
I am facing problem to get variable from query string. I have used htaccess
i am facing this problem here. i want to show item's name by getting
I am facing this problem while installing extensions, themes basically anything from magento connect.
I have an application in C# which I write some data to file. I
i'm new to LINQ and i'm facing a problem, here what i try to

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.