Hi All, Any advice or pointing me in the right direction would be greatly appreciated. Here is what I am trying to do: I want to add $variable to the end of a URL query string and then send it via post method and then retreive the answer. So here is what I have: $curl = curl_init( ); curl_setopt($curl, CURLOPT_URL,"http://www.domain/page.asp?"); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, "a=123&b=345&c=xyz&d={$variable}"); $result = curl_exec ($curl); curl_close ($curl); Code (markup): But its not working, for the life of me I can't figure it out. I have tried everything. Any advice? Am I missing something obvious? Thanks, Morty
Woops, that is just an example, the real variable is all alpha chars I edited the original post, to correct. Any ideas one why curl won't post the query string? Thanks! Morty
If you need to have your data in the URL, it is GET, not POST method. So your example can be: $curl = curl_init( ); $query="a=123&b=345&c=xyz&d={$variable}"; curl_setopt($curl, CURLOPT_URL,"http://www.domain/page.asp?$query"); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $result = curl_exec ($curl); curl_close ($curl); PHP: If I am wrong and you need POST, check that the URL http://www.domain/page.asp doesn't send any redirect as answer; if redirect is there, your data will not be posted. You can try curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true) in such case.
Also you can get more information about last cURL call with echo '<pre>',print_r(curl_getinfo($curl)),'</pre>'; PHP: and curl_error and curl_errno functions.
wmtips, you the man! The issue was that the URL was being redirected, so the CURLOPT_FOLLOWLOCATION worked. Using the get method everything is working fine now. I was using the POST method, after unsuccessfully using the GET method and reading somewhere that the POST method should work for query strings. So to close up the thread and to help anyone in the future, here is the sample code that works: $curl = curl_init( ); $query="a=123&b=345&c=xyz&d={$variable}"; curl_setopt($curl, CURLOPT_URL,"http://www.domain/page.asp?$query"); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $result = curl_exec ($curl); curl_close ($curl); Code (markup): Thanks again! Morty