0

I'm trying to interact with a WS. This WS accept post requests in multipart and also in x-www-urlencoded. The WS is an OCR service, you send a passport picture and the WS returns a json with the MRZ data.

When I try the WS with postman always works, I send any photo of any size (I tested with 5Mb photo) and always works. When I send the exactly the same data using Curl or Guzzle, if the photo is about 30-50Kb the WS works as expected, but when I send a larger image, for example 500Kb, then the WS doesn't work.

I can access to the Ws code because it's propietary. I just trying to understand why is this happen. This is the multipart function

$url='http://10.0.20.113:8080/';
        $req =  new Client(['verify' => 0]);
        $response = $req->post(
            $url, [
                'headers' => [
                    'accept-encoding' => 'gzip, deflate, br',
                    'accept' => '*/*'
                ],
                'multipart' => [
                    [
                        'name' => 'user',
                        'contents' => 'admin'
                    ],
                    [
                        'name' => 'pwd',
                        'contents' => 'admin'
                    ],
                    [
                        'name' => 'doctype',
                        'contents' => '0'
                    ],
                    [
                        'name' => 'new',
                        'contents' => '1'
                    ],
                    [
                        'name' => 'pressmode',
                        'contents' => '2'
                    ],
                    [
                        'name' => 'image1',
                        'contents' => $img1
                    ],
                    [
                        'name' => 'image2',
                        'contents' => $img2,
                    ]

                ],
            ]
        );
        Log::info('Response received');
        return $response->getBody()->getContents();

this is another try with curl

            $ch = curl_init();
            $headers = array();
            $post = array('user' => 'admin', 'pwd' => 'admin', 'doctype' => 0, 'new' => 1, 'pressmode' => 2, 'image1' => $img1, 'image2' => $img2);                    // e.g. $fieldName = 'image'
            curl_setopt_array(
                $ch,
                [
                    CURLOPT_RETURNTRANSFER => true,
                    CURLOPT_HTTPHEADER => $headers,
                    CURLOPT_URL => $url,
                    CURLOPT_POSTFIELDS => $post,
                    CURLOPT_SSL_VERIFYPEER => 0
                ]
            );

            $result = curl_exec($ch);
            $response = curl_getinfo($ch);
Miquel Àngel
  • 149
  • 1
  • 3
  • 11

1 Answers1

0

Finally it was a apache issue in the WS side. Using curl, when the request size is more than 1024 bytes, then curl send a expect:100-continue header.

When the server receives this header, it should respond with an http 100 code, indicating to the client that it can continue transmission.

Postman doesn't use this header even with large requests.

The WS use a embedded apache to serve the requests, which I presume that has a bug (there is at least to bugs related to that) that makes apache doesn't return the http 100 code. Therefore curl aborts the request.

Miquel Àngel
  • 149
  • 1
  • 3
  • 11