Login
Username:

Password:

Remember me



Lost Password?

Register now!
Sections
Who's Online
43 user(s) are online (37 user(s) are browsing Forums)

Members: 1
Guests: 42

salass00, more...
Support us!
Recent OS4 Files
OS4Depot.net





Shorten or Compress a String/URL
Quite a regular
Joined:
2010/5/16 11:20
From Grimsby, UK
Posts: 950
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
   Report Go to top

Re: Shorten or Compress a String/URL
Just can't stay away
Joined:
2006/11/24 18:52
From Gloucestershire, UK.
Posts: 1169
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>
   Report Go to top

Re: Shorten or Compress a String/URL
Amigans Defender
Joined:
2006/12/2 13:27
From Taranto, Italy
Posts: 916
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...
   Report Go to top

Re: Shorten or Compress a String/URL
Quite a regular
Joined:
2010/5/16 11:20
From Grimsby, UK
Posts: 950
I think I need an example code snippet if you please.

   Report Go to top

Re: Shorten or Compress a String/URL
Amigans Defender
Joined:
2006/12/2 13:27
From Taranto, Italy
Posts: 916
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...
   Report Go to top

Re: Shorten or Compress a String/URL
Just popping in
Joined:
2006/12/7 15:39
From Denmark
Posts: 90
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.
   Report Go to top

Re: Shorten or Compress a String/URL
Just popping in
Joined:
2006/12/7 15:39
From Denmark
Posts: 90
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.
   Report Go to top

Re: Shorten or Compress a String/URL
Home away from home
Joined:
2006/12/4 23:15
Posts: 2144
@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.


_________________
Blender For OS4.x : Blues : Walker Broad
   Report Go to top

Re: Shorten or Compress a String/URL
Quite a regular
Joined:
2010/5/16 11:20
From Grimsby, UK
Posts: 950
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.

   Report Go to top

Re: Shorten or Compress a String/URL
Just popping in
Joined:
2006/12/7 15:39
From Denmark
Posts: 90
@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.
   Report Go to top

Re: Shorten or Compress a String/URL
Just popping in
Joined:
2006/12/7 15:39
From Denmark
Posts: 90
@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.
   Report Go to top

Re: Shorten or Compress a String/URL
Quite a regular
Joined:
2010/5/16 11:20
From Grimsby, UK
Posts: 950
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)

   Report Go to top

Re: Shorten or Compress a String/URL
Just popping in
Joined:
2006/12/7 15:39
From Denmark
Posts: 90
Awesome :)

_________________
Alien Air Attack

SAM440@733 mhz as main amiga.
   Report Go to top





[Advanced Search]


Powered by XOOPS 2.0 © 2001-2016 The XOOPS Project