0

I have an API created for export records in xlsx. It is working fine when I call the API directly but if I am using Guzzle/Http to call the API and this was tested using Postman, I get the following error:

   "message": "Malformed UTF-8 characters, possibly incorrectly encoded",
    "exception": "InvalidArgumentException",
    "file": "C:\\xampp\\htdocs\\borneoshop-admin-laravel\\vendor\\laravel\\framework\\src\\Illuminate\\Http\\JsonResponse.php",
    "line": 75, ......

Is there any additional configuration I will have to set? Please help. Thanks.

Edit

I have 2 laravel API projects, for example, A and B. The excel export API (/a/export) has to be called in another laravel API (/b/download) with Guzzle/Http. Using Postman, I was testing both APIs and the "/a/export" API was working fine but if I called "/b/download" which I am using Guzzle/Http here with codes,

$client = new \GuzzleHttp\Client();
$res = $client->post($url, ['form_params' => $parameter]);
$content = $res->getBody()->getContents();
return $content; 

I am getting the error response as shown above.

bhucho
  • 3,903
  • 3
  • 16
  • 34
doremi666
  • 121
  • 3
  • 15
  • provide more details show what you have done to reach at this point – bhucho Feb 20 '21 at 06:35
  • I have 2 laravel API projects, for example, A and B. The excel export API (/a/export) has to be called in another laravel API (/b/download) with Guzzle/Http. Using Postman, I was testing both APIs and the "/a/export" API was working fine but if I called "/b/download" which I am using Guzzle/Http here with codes, $client = new \GuzzleHttp\Client(); $res = $client->post($url, ['form_params' => $parameter]); $content = $res->getBody()->getContents();return $content; I am getting the error response returned as mentioned above. – doremi666 Feb 20 '21 at 07:03
  • whats in $parameter as I believe it has some non UTF-8 texts – bhucho Feb 20 '21 at 08:20
  • I have these parameters passed over. $params = ['start_date' => $request->start_date,'end_date' => $request->end_date]; Both start date and end date have format of "Y-m-d" – doremi666 Feb 20 '21 at 08:24
  • try to use [mb_convert_encoding](https://www.php.net/manual/en/function.mb-convert-encoding.php) `mb_convert_encoding($$request->start_date, "UTF-8");` to convert character encoding – bhucho Feb 20 '21 at 09:15
  • I got it solved now. I directly return the http response content now and removed `response()->json()`. – doremi666 Feb 27 '21 at 04:08
  • how does changing that solved the issue, the issue was something else completely different – bhucho Feb 27 '21 at 06:01
  • my mistake I would say. Thank you for your help. – doremi666 Feb 27 '21 at 10:54

0 Answers0