Now we're going to write an API, but there's a problem with the transfer of multidimensional arrays when using curl to pass arguments
{ $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); }
Start using the time has been the domain parameter loss error, and then look at the data passed, is this
String ' auth-userid=611510&api-key=api&
Domain-name%5b0%5d=domain1&domain-name%5b1%5d=domain2&tlds=com ' (length=93);
And I'm going to pass it on.
' auth-userid=611510&api-key=api&
Domain-name=domain1&domain-name=domain2&tlds=com '
So the transmission will not error, why use Http_build_query (), two-dimensional array will appear this%5b0%5d, and%5b1%5d, how to solve
Reply to discussion (solution)
In fact, the problem is very simple.
Http_build_query? Request string after generating Url-encode
The result is a string of URL encode. All of them have been given 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 passed domain-name[0]=domain1&domain-name[1]=.
You are welcome to join the technology group to learn more about the technology 231566327
%5B0%5D is [] a pair of brackets
This is generated according to PHP rules.
If the other party is not PHP, press domain-name[] to access the Domain-name member
Or you can just erase it.
$result = Str_replace ('%5b0%5d ', ' ', Http_build_query ($post _data));
If the other side is PHP, it must not be deleted. Or we'll have less data.
That's still the address to the URL encode