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
- Now java needs to access my php Interface
- I am here directly
$_POST
Value
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/Get
And the number of threads, and then start running. One of the options is to usemultipart/form-data
If 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 ifHttpClient
I only know the default requestContentType
Yesapplication/x-www-form-urlencode
Of
Problem
- If yes
contentType
Yesapplication/x-www-form-urlencode
Access takes a long time, with an average of several seconds
- If yes
multipart/form-data
It's very fast, just dozens of milliseconds.
Why is this happening?
I use$_GET['username']
It can also be obtained,application/x-www-form-urlencode
Is this actually a Get request?
Reply content: Background
- Now java needs to access my php Interface
- I am here directly
$_POST
Value
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/Get
And the number of threads, and then start running. One of the options is to usemultipart/form-data
If 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 ifHttpClient
I only know the default requestContentType
Yesapplication/x-www-form-urlencode
Of
Problem
- If yes
contentType
Yesapplication/x-www-form-urlencode
Access takes a long time, with an average of several seconds
- If yes
multipart/form-data
It's very fast, just dozens of milliseconds.
Why is this happening?
I use$_GET['username']
It can also be obtained,application/x-www-form-urlencode
Is this actually a Get request?
The default normal form POST isapplication/x-www-form-urlencode
The 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 addedFormData
Can be easily constructedmultipart/form-data
Request 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?