BookmarkSubscribeRSS Feed
Choose Language Hide Translation Bar
zainilmin
Community Trekker

JMP Socket does not return data field from the web page get request? Can we get the json data from web request.

tCall = Socket();

rc = tCall << connect( "URL", "80" );

If( rc[2] == "ok",

    tCall << Send(Char To Blob(

        "GET /abc/123 HTTP/1.0~0d~0a~0d~0a",

        "ASCII~HEX"

    ));

    tMessage = tCall << recv( 486956 );

    print(tMessage);

    text = Blob To Char( tMessage[3], "utf-8" );

    //tCall << Close();

    text;

,

    rc[2]

);

0 Kudos
1 REPLY 1
Craige_Hales
Staff (Retired)

Re: JMP Socket does not return data field from the web page get request? Can we get the json data from web request.

try something like this:

tCall = Socket();

rc = tCall << connect( "jmp.com", "80" );

buffer = Char To Blob( "" );

While( rc[2] == "ok", // loop to receive all the data

  tCall << Send( Char To Blob( "GET / HTTP/1.0~0d~0a~0d~0a", "ASCII~HEX" ) );

  // 10000, below, is the max you'll get.  You will get what ever is actually available,

  // which usually won't be everything because of far-end delay and transmission time.

  rc = tCall << recv( 10000 );

  buffer = buffer || rc[3]; // concatenate all data

);

Show( rc ); // expecting {"recv", "CLOSED:  no data received." ...

text = Blob To Char( buffer, "utf-8" ); // convert

Show( text );

That code is not right.  This is better:

tCall = Socket();

rc = tCall << connect( "jmp.com", "80" );

buffer = Char To Blob( "" );

If( rc[2] == "ok", // connected OK?

  rc = tCall << Send( Char To Blob( "GET / HTTP/1.0~0d~0a~0d~0a", "ASCII~HEX" ) );

  While( rc[2] == "ok", // loop to receive all the data

  // 10000, below, is the max you'll get.  You will get what ever is actually available,

  // which usually won't be everything because of far-end delay and transmission time.

  rc = tCall << recv( 10000 );

  buffer = buffer || rc[3]; // concatenate all data

  );

  If( Left( rc[2], 7 ) == "CLOSED:", // ended as expected?

  text = Blob To Char( buffer, "utf-8" ); // convert

  Show( text ); // success!

  ,

  Show( "error", rc )

  );

,

  Show( "could not connect!" )

);

Craige