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 6791395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:50:29+00:00 2026-05-26T17:50:29+00:00

I want to call the google url shortner API from my C# Console Application,

  • 0

I want to call the google url shortner API from my C# Console Application, the request I try to implement is:

POST https://www.googleapis.com/urlshortener/v1/url

Content-Type: application/json

{“longUrl”: “http://www.google.com/“}

When I try to use this code:

using System.Net;
using System.Net.Http;
using System.IO;

and the main method is:

static void Main(string[] args)
{
    string s = "http://www.google.com/";
    var client = new HttpClient();

    // Create the HttpContent for the form to be posted.
    var requestContent = new FormUrlEncodedContent(new[] {new KeyValuePair<string, string>("longUrl", s),});

    // Get the response.            
    HttpResponseMessage response = client.Post("https://www.googleapis.com/urlshortener/v1/url",requestContent);

    // Get the response content.
    HttpContent responseContent = response.Content;

    // Get the stream of the content.
    using (var reader = new StreamReader(responseContent.ContentReadStream))
    {
        // Write the output.
        s = reader.ReadToEnd();
        Console.WriteLine(s);
    }
    Console.Read();
}

I get the error code 400: This API does not support parsing form-encoded input.
I don’t know how to fix this.

  • 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-05-26T17:50:29+00:00Added an answer on May 26, 2026 at 5:50 pm

    you can check the code below (made use of System.Net).
    You should notice that the contenttype must be specfied, and must be “application/json”; and also the string to be send must be in json format.

    using System;
    using System.Net;
    
    using System.IO;
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://www.googleapis.com/urlshortener/v1/url");
                httpWebRequest.ContentType = "application/json";
                httpWebRequest.Method = "POST";
    
                using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                {
                    string json = "{\"longUrl\":\"http://www.google.com/\"}";
                    Console.WriteLine(json);
                    streamWriter.Write(json);
                }
    
                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                {
                    var responseText = streamReader.ReadToEnd();
                    Console.WriteLine(responseText);
                }
    
            }
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to call a API with a POST request. But my Chrome Inspector
I want to get xml data from google server using it's API. so, i
I want to use the fcbk_autocomplete function I downloaded from http://www.emposha.com/javascript/fcbkcomplete.html in Google Maps
I want to call a google service using javascript with a keyword and a
I want to call external urls using cron job of Google App Engine. And
I want to call a function from a .NET DLL (coded in C#) from
I want to call a web service, but I won't know the url till
I want to call a c# function from my javascript function. I have a
I want to call my .NET code from unmanaged C++. My process entrypoint is
I want to call some RESTful web services from a J2ME client running on

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.