PHP uses CURL to pass multi-dimensional arrays. now we need to write an API, but there is a problem in passing multi-dimensional arrays when using curl to pass parameters.
{ $post_data = array( 'auth-userid' => 611510, 'api-key' => 'api', 'domain-name'=>array('domain1','domain2'), 'tlds' => 'com', ); $result=http_build_query($post_data); var_dump($result); }
When I started to use it, the domain parameter loss error always occurs. then let's take a look at the passed data.
String 'auth-userid = 611510 & api-key = api &
Domain-name % 5B0% 5D = domain1 & domain-name % 5B1% 5D = domain2 & tlds = com '(length = 93 );
What I want to upload is
'Auth-userid = 611510 & api-key = api &
Domain-name = domain1 & domain-name = domain2 & tlds = com'
If http_build_query () is used, the error "% 5B0% 5D" and "% 5B1% 5D" appear in the two-dimensional array. how can this problem be solved?
Reply to discussion (solution)
In fact, this problem is very simple.
Http_build_query? Request string generated after URL-encode
Generates a url encode string. It is already provided to encode.
You can use
$post_data = array( 'auth-userid' => 611510, 'api-key' => 'api', 'domain-name'=>array('domain1','domain2'), 'tlds' => 'com', ); $result=http_build_query($post_data); var_dump($result); var_dump(urldecode($result));
In this way, the data is transmitted in the domain-name [0] = domain1 & domain-name [1] = format.
You are welcome to join the technology group to learn more technology 231566327.
% 5B0% 5D is [] a pair of square brackets
This is generated according to php rules.
If the other party is not a php user, pressDomain-name []This name is used to access the domain-name member.
Or you can delete it.
$ Result = str_replace ('% 5B0% 5D', '', http_build_query ($ post_data ));
If the other party is in php, it cannot be deleted. Otherwise, there will be less data.
The url is still given to encode.