There is a function called URLConnection addRequestProperty(String key, String value)
in Java, which could add values into an existing key, like conn.addRequestProperty("Cookie", requestMap.get("responseCookie"))
How can I implement this function in PHP? I'm using the cURL, which has curl_setopt($ch, CURLOPT_HTTPHEADER, $headers)
, but it will delete the original values stored in the key. How can I append values into a key? Or I need to implement another class? Thanks!
Asked
Active
Viewed 523 times
1

Prince Luo
- 101
- 1
- 8
-
You had better show us some actual code – RiggsFolly Jun 17 '17 at 14:41
-
@RiggsFolly I can show you the logic, cause I don't write any PHP code yet. Every time a request comes into the server, we read the cookie. If a cookie key called "Cookie" exist, we need to keep its key, and add value called "responseCookie" from a third-party interface; if not, we create the cookie "Cookie" and store the "responseCookie" into the key. Now my job is to convert the Java code into PHP code. – Prince Luo Jun 18 '17 at 02:28
1 Answers
0
The curl functions do not manage that for you (see as well Can I call curl_setopt with CURLOPT_HTTPHEADER multiple times to set multiple headers?), so you would need to implement that your own and/or use an existing library that is curl based which has such a functionality.

hakre
- 193,403
- 52
- 435
- 836
-
So that means I need to read the values stored in the key first, and add the new one into the values and put them back to the key? – Prince Luo Jun 18 '17 at 02:21
-
If you want to handle it your own, you need to do the bookkeeping of set headers so that you can add more later on. – hakre Jun 18 '17 at 06:24
-
Fortunately, I know all the keys to be updated, and they won't be too many. Thanks a lot! – Prince Luo Jun 18 '17 at 09:32