|
Shorten or Compress a String/URL |
Posted on: 2015/11/4 20:38
#1 |
---|---|---|
Quite a regular
![]() ![]() Joined:
2010/5/16 12: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
|
|
|
Re: Shorten or Compress a String/URL |
Posted on: 2015/11/4 22:24
#2 |
---|---|---|
Just can't stay away
![]() ![]() Joined:
2006/11/24 18:52 From Gloucestershire, UK.
Posts: 1172
|
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> |
||
|
Re: Shorten or Compress a String/URL |
Posted on: 2015/11/5 18:24
#3 |
---|---|---|
Amigans Defender
![]() ![]() Joined:
2006/12/2 13:27 From Taranto, Italy
Posts: 933
|
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... ![]() |
||
|
Re: Shorten or Compress a String/URL |
Posted on: 2015/11/5 21:19
#4 |
---|---|---|
Quite a regular
![]() ![]() Joined:
2010/5/16 12:20 From Grimsby, UK
Posts: 950
|
I think I need an example code snippet if you please.
|
|
|
Re: Shorten or Compress a String/URL |
Posted on: 2015/11/6 7:59
#5 |
---|---|---|
Amigans Defender
![]() ![]() Joined:
2006/12/2 13:27 From Taranto, Italy
Posts: 933
|
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... ![]() |
||
|
Re: Shorten or Compress a String/URL |
Posted on: 2015/11/6 9:42
#6 |
---|---|---|
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. |
|
|
Re: Shorten or Compress a String/URL |
Posted on: 2015/11/6 10:02
#7 |
---|---|---|
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
|
|
|
Re: Shorten or Compress a String/URL |
Posted on: 2015/11/6 20:35
#8 |
---|---|---|
Home away from home
![]() ![]() Joined:
2006/12/4 23:15 Posts: 2212
|
@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. |
|
|
Re: Shorten or Compress a String/URL |
Posted on: 2015/11/6 22:22
#9 |
---|---|---|
Quite a regular
![]() ![]() Joined:
2010/5/16 12: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.
|
|
|
Re: Shorten or Compress a String/URL |
Posted on: 2015/11/7 0:12
#10 |
---|---|---|
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 :)
|
|
|
Re: Shorten or Compress a String/URL |
Posted on: 2015/11/7 0:13
#11 |
---|---|---|
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.
|
|
|
Re: Shorten or Compress a String/URL |
Posted on: 2015/11/7 0:20
#12 |
---|---|---|
Quite a regular
![]() ![]() Joined:
2010/5/16 12: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) |
|
|
Re: Shorten or Compress a String/URL |
Posted on: 2015/11/7 11:26
#13 |
---|---|---|
Just popping in
![]() ![]() Joined:
2006/12/7 15:39 From Denmark
Posts: 90
|
Awesome :)
|
|