服务器拒绝了此请求,因为请求实体的格式不受请求的支持

时间:2018-09-16 14:20:39

标签: php curl header request

我通过php curl发送此请求

    $message_data=[
        "sendProjectMessageProjectThreadId"=>"102915g147219p133027",
        "sendProjectMessageText"=>"test message"

    ];
    $data=$this->get_content($this->url_message,$message_data);
 public function get_content($url,$data=[]){

        $data_string = json_encode($data);
 $delimiter = '-------------'.uniqid();
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch,CURLOPT_COOKIEFILE,__DIR__.'/cookie_message.txt');
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Content-Type: multipart/form-data;  boundary='. $delimiter,
        'Content-Type: application/json',
         'Content-Length: ' .strlen($data_string)
        ));

        $result = curl_exec($ch);

        return $result;


    }

并收到错误消息:服务器拒绝了此请求,因为请求实体的格式不受请求方法的请求资源支持。

请看看我如何在原始请求http://prntscr.com/kv0wjr中获得请求有效载荷

现在我得到这个错误http://prntscr.com/kv5ezc

0 个答案:

没有答案