Content-type-java php access interface problem, $ _ POST receives contentType by default?

Source: Internet
Author: User
Tags form post
Background now java needs to access my php interface. The $ _ POST value testing tool on my side is under mac. I am not quite clear. It is an HTTP service testing tool. Fill in my api address, parameter, then access the type PostGet, then the number of threads or something, and then start running. One of the options is to make... background
  1. Now java needs to access my php Interface
  2. I am here directly$_POSTValue

The test tool is under mac. I am not quite clear about it. It is an HTTP service testing tool. Fill in my api address, parameters, and access type.Post/GetAnd the number of threads, and then start running. One of the options is to usemultipart/form-dataIf checked, it will be very fast.

Php end

Php is actually a common method on my side, which is similar to this:

function check_username(){    $username = $_POST['username'];    $result = _check_username($username);    return json($result);}
Java end

The encapsulated class library, as ifHttpClientI only know the default requestContentTypeYesapplication/x-www-form-urlencodeOf

Problem
  • Discover with test tools
  1. If yescontentTypeYesapplication/x-www-form-urlencodeAccess takes a long time, with an average of several seconds
  2. If yesmultipart/form-dataIt's very fast, just dozens of milliseconds.

Why is this happening?

I use$_GET['username']It can also be obtained,application/x-www-form-urlencodeIs this actually a Get request?

Reply content: Background
  1. Now java needs to access my php Interface
  2. I am here directly$_POSTValue

The test tool is under mac. I am not quite clear about it. It is an HTTP service testing tool. Fill in my api address, parameters, and access type.Post/GetAnd the number of threads, and then start running. One of the options is to usemultipart/form-dataIf checked, it will be very fast.

Php end

Php is actually a common method on my side, which is similar to this:

function check_username(){    $username = $_POST['username'];    $result = _check_username($username);    return json($result);}
Java end

The encapsulated class library, as ifHttpClientI only know the default requestContentTypeYesapplication/x-www-form-urlencodeOf

Problem
  • Discover with test tools
  1. If yescontentTypeYesapplication/x-www-form-urlencodeAccess takes a long time, with an average of several seconds
  2. If yesmultipart/form-dataIt's very fast, just dozens of milliseconds.

Why is this happening?

I use$_GET['username']It can also be obtained,application/x-www-form-urlencodeIs this actually a Get request?

The default normal form POST isapplication/x-www-form-urlencodeThe form for uploading files ismultipart/form-data.
Because different encoding and decoding methods are used, the former is suitable for key-value pairs with less data and the latter for binary files.
In the browser, both methods are well supported, and HTML5 is addedFormDataCan be easily constructedmultipart/form-dataRequest Form.
For PHP, the entire lifecycle of the two variables from servers such as Apache or nginx to the big variables in $ _ POST is the same. Only the send-parse step does different work.
Although there is a certain efficiency gap between the two, the gap between the two orders of magnitude is still very rare.

So I think this problem occurs. You can test it in a browser or check the actual efficiency in the java access log and php response log, instead of testing tools (I don't know what test tool you are using), check whether the problem lies in java construction, php parsing the request and returning it, or the intermediate network.

Can you paste your code? You cannot answer this question.
Can you use wireshark to capture packets?

  • First, are you sure your packets are large?
  • Is your php apache, fpm, or fastcgi?

Can I add more details?

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.