Click here to Skip to main content
15,669,693 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I would like to make a URL Shortener in C++ that uses an API to short url the api request is this:

How can I make it in C++ So the user will be asked to insert the long url and then press Enter to short it and there will be automatically return the short URL Anyone can help me please? Regards P.S I have this code:
#include <iostream>
using namespace std;
int main ()
    string longurl, shorturl;
    cout<<"Please insert long URL"<<endl;
    shorturl = ""+longurl;
    cout<<"Short URL:"<<shorturl<<endl;
    return 0;

But return me How can I make it to connect to the website and return me the shorted URL?
Updated 31-Jan-14 9:46am
Philippe Mori 31-Jan-14 22:17pm    
URL shortening is a service that some web site provide. So you simply have to connect to one of those site, send the information and then interpret the answer. For more détails some of the solution belows might help.

Share this answer
You seem not to understand the concept of client-server.

Your program would play the client role that requests some data from the server.

The client requests data from the server.
The server returns a resopnse (error or success plus resuested data).

In order to successfully talk to each other, both roles must agree on some communication protocol.

The request protocol is encoded in the URL plus some additional data sent to the server.
The response protocol is based on the protocol mentioned in the requestng URL plus the additional data sent to the server.

See HTTP Protocol[^] for some background on HTTP communication between client and server.

To implement a web client, you may work on the bare low level functions, or depending on your environment (Windows, Linux, Unix, ...) you may use some existing classes/libraries.

Unix/Linux: see e.g.[^] for C based server/client code example.

CURL: or you might use the libcurl, see[^].

CP: you might also use some already invented client, e.g. A Fully Featured Windows HTTP Wrapper in C++[^].

Or on Windows/.Net, you might use[^]

Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900