Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
37 user(s) are online (19 user(s) are browsing Forums)

Members: 1
Guests: 36

trixie, more...

Support us!

Headlines

 
  Register To Post  

Shorten or Compress a String/URL
Quite a regular
Quite a regular


See User information
Hello,

If I have a long string which exceeds 8190 characters (the Apache default) that I would like to pass as a URL the HTTP server quite rightly complains.

What approach can I take to shorten or compress the string?

You should know that I am using Hollywood, I tried BaseStr64(), but that in fact made the string even longer much to my amusement.

I could split the data into several chunks and call the PHP multiple times, but that could be a re-write when I am sure there is another way.


Edited by djrikki on 2015/11/4 21:49:42
Go to top
Re: Shorten or Compress a String/URL
Just can't stay away
Just can't stay away


See User information
You could gzip it, iirc it's a standard compression used for sending web pages, don't see why you shouldn't be able to use it the other way...

Amiga user since 1985
AOS4, A-EON, IBrowse & Alinea Betatester

Ps. I hate the new amigans website. <shudder>
Go to top
Re: Shorten or Compress a String/URL
Amigans Defender
Amigans Defender


See User information
If apache has the limit of 8k, you can't exceed this value (and i suppose you can't change it..).
As Severin said use gzip to compress it. But do a gzip+base64 and not the countrary if you need to pass it via querystring. Of course if Apache supports gzip compression you can use a POST to send data using gzip directly

i'm really tired...
Go to top
Re: Shorten or Compress a String/URL
Quite a regular
Quite a regular


See User information
I think I need an example code snippet if you please.

Go to top
Re: Shorten or Compress a String/URL
Amigans Defender
Amigans Defender


See User information
Well i don't know if Hollywood has a library to gzip data. You should search on google how to do this maybe in classic C. Which example do you need?

i'm really tired...
Go to top
Re: Shorten or Compress a String/URL
Just popping in
Just popping in


See User information
I would think that posting the data would be the better choice.

PM me, I might be able to help you.

Alien Air Attack

SAM440@733 mhz as main amiga.
Go to top
Re: Shorten or Compress a String/URL
Just popping in
Just popping in


See User information
It should be possible to use SendData(id, data$) to send a post request, since POST data is part of the request body.

You should be able to send something like this:

POST /path/script.cgi HTTP/1.0
From: xxxyyyzzz
User-Agent: HTTPTool/1.0
Content-Type: application/x-www-form-urlencoded
Content-Length: 32

var1=something&var2=something


At least that is how I use REST webservices in Delphi, granted Delphi and Hollywood is not the same, but I would think the approach should be the same.


Edited by yssing on 2015/11/7 11:26:49
Alien Air Attack

SAM440@733 mhz as main amiga.
Go to top
Re: Shorten or Compress a String/URL
Home away from home
Home away from home


See User information
@djrikki

A string that long should POSTed not GETed (sic)

Are you bound to hollywood? Python or perl would much easier to use to handle this having http user agent classes inplace to handle such stuff.


Go to top
Re: Shorten or Compress a String/URL
Quite a regular
Quite a regular


See User information
I will go the POST route via SendData() I don't see why that shouldn't work that way - although I haven't done this before so here goes.

Go to top
Re: Shorten or Compress a String/URL
Just popping in
Just popping in


See User information
@djrikki If you get it working, please consider making a unit/class that uses SendData and publish it, so it is easier for others to do in the future :)

Alien Air Attack

SAM440@733 mhz as main amiga.
Go to top
Re: Shorten or Compress a String/URL
Just popping in
Just popping in


See User information
@broadblues The solution to this might be to create a class/unit that handles this and the publish it.

Alien Air Attack

SAM440@733 mhz as main amiga.
Go to top
Re: Shorten or Compress a String/URL
Quite a regular
Quite a regular


See User information
Thanks all, objective achieved, yes I went the POST route, updated my PHP script to $_POST instead of $_GET, plus the Hollywood code below, if its any use to anyone else, go ahead and modify.

OpenConnection(1, "example.com", 80)

Local trans = SendData(1, "POST http://www.example.com/script.php HTTP/1.0\nContent-Type: application/x-www-form-urlencoded\nContent-Length: " .. 6 + 10 + StrLen(var1$) + StrLen(var2$) .. "\n\nvar1=" ..var1$ .. "&var2=" .. var2$)

Local gotline$, count, done
/* SKIP HTTP HEADER */
gotline$, count, done = ReceiveData(1, #RECEIVELINE)
While gotline$ <> "Content-Type: text/html"
gotline$, count, done = ReceiveData(1, #RECEIVELINE)
Wend
gotline$, count, done = ReceiveData(1, #RECEIVELINE)
gotline$, count, done = ReceiveData(1, #RECEIVELINE)
/* SKIP HTTP HEADER */

gotline$, count, done = ReceiveData(1, #RECEIVELINE)

While gotline$ <> ""
/* loop through lines */
gotline$, count, done = ReceiveData(1, #RECEIVELINE)
Wend

CloseConnection(1)

Go to top
Re: Shorten or Compress a String/URL
Just popping in
Just popping in


See User information
Awesome :)

Alien Air Attack

SAM440@733 mhz as main amiga.
Go to top

  Register To Post

 




Currently Active Users Viewing This Thread: 1 ( 0 members and 1 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2024 The XOOPS Project