页面未显示,因为从Web服务器向IIS后端发送大POST请求时请求实体太大

时间:2016-10-13 07:27:28

标签: php android codeigniter curl iis-8

我的故事是我们有三个客户端(android / ios / web)使用Restful Microsoft后端和套件API。

有一个上传图片api,android / ios应用程序成功上传大图片但是从我们的网络服务器(PHP / CodeIgniter)无法用他们的服务器上传大图像。 当我们发送小于30KB的小图像时,POST请求成功但是对于较大的图像,POST请求总是返回“由于请求实体太大,页面未显示”。和错误代码413。

以下是我的上传功能:

/**
     * This function will post an image to Social Plus
     * 1. Copy image, which is sent from user's browser, to "upload_path" directory
     * 2. Read content of "image file" and insert into body of POST's request
     * 3. Send a POST request of binary to SS+ via Curl library
     * 4. Return blobHandle and file's info back to browser
     */
    function img_upload(){
        $data = array();
        $config['upload_path']          = './assets/upload_files/'; //location of image file
        $config['allowed_types']        = 'jpeg|png|gif|jpg';
        $config['encrypt_name']         = true; //convert normal name file to encrypted file name
        $config['max_size']             = 104857600; //1000MB
        $session_token = $this->input->post("session_token");
        $authorization = "Bearer " . $session_token;
        $this->load->library('upload', $config);
        if ( ! $this->upload->do_upload('file'))
        {
            $error = array('error' => $this->upload->display_errors());
            echo json_encode($error);
        }
        else
        {
            $data = $this->upload->data();
            //Reading content binary of image
            $raw_data = file_get_contents($data['full_path']);
            $headers = array('Authorization: '.$authorization,'Content-Type: '.$data['file_type'],
                'Content-Length: ' . strlen($raw_data));
            $image_data = array(
                'image' => base64_encode($raw_data)
            );



            $curl = curl_init ();
            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
            curl_setopt($curl,CURLOPT_FOLLOWLOCATION,0);
            curl_setopt ($curl, CURLOPT_URL, BASE_SOCIAL_PLUS_USER_PHOTO_URL);
            curl_setopt($curl, CURLOPT_HTTPHEADER,$headers);
            curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt ($curl, CURLOPT_POST, 1);
            curl_setopt( $curl , CURLOPT_VERBOSE , 0 );
            curl_setopt ($curl, CURLOPT_POSTFIELDS,$raw_data);
            $photo_details = curl_exec($curl);
            $photo=json_decode($photo_details,true);

            $datestring = '%Y-%m-%d %h:%i:%s:%u %a';
            $time = time();

            if(curl_errno($curl))
            {
                echo 'error:xxx' . curl_error($curl);
            }
            curl_close ( $curl );

            if(!isset($photo['blobHandle']))
            {
                $error = array('error' =>"Oop...Failed to upload image!");
                unlink($data['full_path']);
                $error["time_stamp"] = mdate($datestring, $time);
                $error["api_return"] = $photo_details;
                echo json_encode($error);
            } else {
                $photo_handle=$photo['blobHandle'];
                $data['blob_Handle'] = $photo_handle;
                $data["time_stamp"] = mdate($datestring, $time);
                $data["api_return"] = $photo;
                unlink($data['full_path']); //Delete uploaded file
                echo json_encode(
                    array("file_name"=>$data['orig_name'],
                        "file_size"=>round($data['file_size']),
                        "blob_handle"=>$photo_handle,
                        "file_type" => $data["file_type"],
                        "time_stamp" => $data['time_stamp'],
                        "api_return" => $data['api_return']));
            }
        }
    }

微软的人不认为这是他们的后端错误。 我曾使用WireShark从Android和我的本地网络服务器捕获所有包。但也有类似的包发送出去。截至目前,我们知道IIS 8.5的POST主体请求有限,这使得IOS / Android应用程序可以在每个平台上的HTTP库上发送POST大图像请求。

我也尝试使用CURL命令通过选项-T(数据文件)发送POST请求,但它没有帮助。

从WireShark结果中,有一个从我的Web服务器发送到ISS后端的加密警报包,并在该连接立即删除之后。 enter image description here

我们试图修复这个问题一个星期,但它没有帮助。:((

0 个答案:

没有答案