Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

110
Views
How Can I set and send GET data when characters of an URI exceed 5,000

I am using a Laravel blade.

My code below happens error when the size of item of textarea is huge. I am looking for a way to solve it.

Everyone. How should I send a huge text to server? How should I modify my codes?

Blade(JavaScript)

    function sendByGet()
    {
        var items =  document.getElementById("item").value;
        var param = "?items="+items+"&id={{$id}}";
        var url = {{(url)}} + encodeURI(param);

        let result = fetch(url);
        result.then(response => response.json()).then(
                responceObject =>{
                    
                    }
                } 
    }

Controller PHP

 public function receivebyGet(Request $request)
    {
        $lineArray  = array();
        $slipData = explode("\n", $request->items); 

Error

the date is replaces <huge_text> (Actual data is text(5000 characters))

phpbladeName?id=01:270 GET https://test.com/test/send_by_get?&item=<huge_text> 414 sendByGet @ confirmation?id=01:270 onclick @ confirmation?id=0:244 VM142:1 Uncaught (in promise) SyntaxError: Unexpected end of JSON input at phpbladeName?id=01

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Move your data to the BODY

function sendByGet(url) {
    const items =  document.getElementById("item").value;
    const param = encodeURI("?id={{$id}}");

    fetch(url + param, {
        method: 'GET',
        headers: { 'Content-Type': 'plain/text' },
        body: items,
    })
        .then(response => response.json())
        .then( ... );
}

PHP Controller (assuming being Laravel)

public function receivebyGet(Request $request) {
    $lineArray = array();
    $slipData = explode("\n", $request->getContent());
    ...
}

Query size limit

As mentioned by Peter Krebs the maximum URL size (which includes the Query) is 2000 characters. So you cannot expect your system to reliably work if url is longher than 2000. Read more here.

GET body

As pointed out by Jabaa you should semantically choose the method, not technically. But this is something that has evolved over time (initially the GET body was supposed to be rejected/ignored) read more here. Hence you should consider it carefully and verify that all the parties involved (server, browser, proxies, cache) supports it properly. This is why oftentimes developers choose to violate semantics and use a POST method.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!