cpanon Posted April 19, 2007 Share Posted April 19, 2007 Hello I am receiving a response from a post into $response. I need to extract the key/value pairs and format up a new parameter string and send it to another servlet. Can I extract the key/value with something like this? $response_vars = (explode '&', $_response) $pairvalue = (explode '=', $_response_vars) foreach ($pairvalue as $k => $v){ $data .= $key . '=' . urlencode($value) . '&'; } and then use this to execute a well formed url and post it? curl_setopt($curl_handle, CURLOPT_URL, "https://mydomain.com/context/myAction.do?"); curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $data); $response_2nd = curl_exec ($curl_handle) or die ("There has been an error connecting"); Link to comment https://forums.phpfreaks.com/topic/47681-parsing-keyvalue/ Share on other sites More sharing options...
kenrbnsn Posted April 19, 2007 Share Posted April 19, 2007 What do you mean by I am receiving a response from a post into $response What does a sample data look like? What does the form look like? Please post all code between tags. Ken Link to comment https://forums.phpfreaks.com/topic/47681-parsing-keyvalue/#findComment-232833 Share on other sites More sharing options...
cpanon Posted April 19, 2007 Author Share Posted April 19, 2007 Hello It will look something like this: HTTP/1.0 200 OK Approved Connection: close Content-Type: application/x-www-form-urlencoded Content-Length: 160 auth_msg=TEST+APPROVED&ticket_code=XXXXXXXXXXXXXXX&avs_code=X&auth_date=2004-06-09+22%3A55%3A08&status_code=T &trans_id=109704163690&auth_code=999999&cvv2_code=M Link to comment https://forums.phpfreaks.com/topic/47681-parsing-keyvalue/#findComment-232839 Share on other sites More sharing options...
cpanon Posted April 19, 2007 Author Share Posted April 19, 2007 Hello Sorry for being a pest,however can anyone help me understand how to parse out the key/value pairs from the response below. I will then take those key/value pairs and post them to another url. tia. HTTP/1.0 200 OK Approved Connection: close Content-Type: application/x-www-form-urlencoded Content-Length: 160 auth_msg=TEST+APPROVED&ticket_code=XXXXXXXXXXXXXXX&avs_code=X&auth_date=2004-06-09+22%3A55%3A08&status_code=T &trans_id=109704163690&auth_code=999999&cvv2_code=M Link to comment https://forums.phpfreaks.com/topic/47681-parsing-keyvalue/#findComment-233049 Share on other sites More sharing options...
kenrbnsn Posted April 25, 2007 Share Posted April 25, 2007 Get this auth_msg=TEST+APPROVED&ticket_code=XXXXXXXXXXXXXXX&avs_code=X&auth_date=2004-06-09+22%3A55%3A08&status_code=T &trans_id=109704163690&auth_code=999999&cvv2_code=M part of the response into a string and then use the function parse_str() to get the values. Ken Link to comment https://forums.phpfreaks.com/topic/47681-parsing-keyvalue/#findComment-237769 Share on other sites More sharing options...
cpanon Posted April 25, 2007 Author Share Posted April 25, 2007 Hi Ken Thanks, however I am not clear. I am getting the entire response, http headers and content. How do I split off just that part into a string? When I have that isnt that enough to then send on to my next servlet? Is it wrong to assume that that portion is properly url-encoded? I am not going to add to the key/value pairs, I just want to send them on properly formatted to my next phase? tia Link to comment https://forums.phpfreaks.com/topic/47681-parsing-keyvalue/#findComment-237790 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.