POST some JSON through TELNET

14,362

I can't understand why you want to use Telnet. Telnet can be useful to quickly test chatty protocols, and even if HTTP is chatty to some degree, it's very cumbersome to upload an image (plus, from the given service name, setMap, I guess the service doesn't really let you upload an image, but just insert a record in the database pointing to an image accessible on another service).

What you are asking is something like:

$ telnet example.com 80
> POST /setMap HTTP/1.1
> Host: www.example.com
> Content-Type: application/json; charset=utf-8
> Content-Length: 1234
> 
> {"mapName":"myMapName","mapURL":"http://tinypic.com/myimg"}
>

Note that it's just an example. You have to replace connection parameters (host, port), content-type, content-length and the actual JSON data - and this we can't know because depends on the actual service implementation.

Share:
14,362
merveotesi
Author by

merveotesi

A violet boson

Updated on July 26, 2022

Comments

  • merveotesi
    merveotesi over 1 year

    I am told to upload an image to a server by sending a JSON as a request.

    JSON is sth like below:

    {"action":"setMap","data":{"mapName":"myMapName","mapURL":"http://tinypic.com/myimg"}}
    

    I do not know how to use TELNET to POST a JSON.

    i guess i should write something like below

    terminal>telnet my.ip.num.ber port
    
    POST /setMap HTTP/1.1
    

    but dont know how to continue.

    Should i write

    DATA : {"action":"setMap","data":{"mapName":"myMapName","mapURL":"http://tinypic.com/myimg"}}
    

    How can i get the JSON sent?

  • merveotesi
    merveotesi over 9 years
    should i expect a return like OK 200 or sth other like this.There is no action after i paste the last line and enter. Thanks
  • merveotesi
    merveotesi over 9 years
    also i am using a built in application and as i understood it makes some settings when users call these actions with parameters
  • Raffaele
    Raffaele over 9 years
    Yes, the server should at least respond with the HTTP response line. If nothing happens, and you can't check the service database, maybe you computed a wrong content-length and so the remote end is still waiting for you to complete your request
  • Jerry Jeremiah
    Jerry Jeremiah almost 8 years
    @merveotesi If nothing happes after you paste in the last line then your Content-Length is wrong. Remember the Content-Length only includes the actual data and does not include the header or the blank line between the header and the body. So for his example the Content-Length should be 59 and the JSON in your question is 86