How does php curl call the interface to display HTTP Status 415?

Source: Internet
Author: User

Use php curl to call the interface provided by the other party and receive the following error message:

HTTP Status 415

The server refused this request because the request entity is in a format not supported by the requested resource for the requested method.

Curl code snippets are as follows:

$ Ch = curl_init ();
Curl_setopt ($ ch, CURLOPT_URL, $ url );
Curl_setopt ($ ch, CURLOPT_HEADER, FALSE );
Curl_setopt ($ ch, CURLOPT_NOBODY, FALSE );
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, TRUE );
Curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, TRUE );
Curl_setopt ($ ch, CURLOPT_AUTOREFERER, TRUE );
Curl_setopt ($ ch, CURLOPT_TIMEOUT, 120 );
Curl_setopt ($ ch, CURLOPT_POST, TRUE );
Curl_setopt ($ ch, CURLOPT_POSTFIELDS, json_encode ($ postData ));

$ Data = curl_exec ($ ch );
Curl_close ($ ch );

No problems were found in the description of the interface set in curl for multiple checks. The server on the other side uses Tomcat 7. At one time, it was suspected that the web configuration of the other side was incorrect. Later, I studied the document carefully, and mentioned that Response is the jason format document, but the Request Header information is not specified in the above curl, so try to add a header and solve the problem. The code is as follows:

Curl_setopt ($ ch, CURLOPT_HTTPHEADER, array ("Content-Type: application/json; charset = utf-8 "));

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.