sonnieboy Posted December 11, 2013 Share Posted December 11, 2013 Hello experts, Please bear with me on this question. I wrote this code in classic asp sometime ago. I have since gotten away from classic asp and was asked to use similar code in php. First here is the asp version: <% Set http = Server.CreateObject("msxml2.ServerXMLHTTP") http.Open "POST", "Authorize", False http.setRequestHeader "Content-type","application/x-www-form-urlencoded" http.Send Request.Form Response.Write http.ResponseText Response.End %> Here is my attempt at converting to php: <? Set $http = Server.CreateObject("msxml2.ServerXMLHTTP"); $http.$Open "POST", "Authorize", False; $http.$setRequestHeader "Content-type","application/x-www-form-urlencoded"; $http.$Send Request.Form; echo $http.$ResponseText; Response.End; ?> Of course it didn't work. Could you please assist me with this? I really appreciate your assistance in advance Quote Link to comment https://forums.phpfreaks.com/topic/284706-how-do-i-convert-this-to-php/ Share on other sites More sharing options...
KevinM1 Posted December 11, 2013 Share Posted December 11, 2013 Of course it didn't work. ASP and PHP are completely different languages. You can't expect to slap '$' in front of everything and have it work. What are you trying to do? As in, what is the programming task you're trying to accomplish? Because it's likely there's no 1-to-1 translation. Quote Link to comment https://forums.phpfreaks.com/topic/284706-how-do-i-convert-this-to-php/#findComment-1462092 Share on other sites More sharing options...
sonnieboy Posted December 11, 2013 Author Share Posted December 11, 2013 Hi Kevin, Thanks a lot for the response. We have a webservice called Authorize method and due to same domain policy restrictions, we are unable to make direct ajax call to this webservice. Only way is to use proxy Server. The asp code allows for us to accomplish this. The proxyAuthorize.asp file points to the webservice method, Authorize and ajax calls the webservice via the proxyAuthorize.asp. Unfortunately, our current server was configured to run only php and they are asking me to change the code from asp to php. Again, thanks for trying to assist. Quote Link to comment https://forums.phpfreaks.com/topic/284706-how-do-i-convert-this-to-php/#findComment-1462097 Share on other sites More sharing options...
.josh Posted December 11, 2013 Share Posted December 11, 2013 you're going to need to use cURL for this. Quote Link to comment https://forums.phpfreaks.com/topic/284706-how-do-i-convert-this-to-php/#findComment-1462128 Share on other sites More sharing options...
sonnieboy Posted December 11, 2013 Author Share Posted December 11, 2013 Thanks Josh, A few examples i tried hasn't worked. Do you mind pointing me to correct example? Quote Link to comment https://forums.phpfreaks.com/topic/284706-how-do-i-convert-this-to-php/#findComment-1462131 Share on other sites More sharing options...
captbeagle Posted December 12, 2013 Share Posted December 12, 2013 (edited) I'm not terribly knowledgeable about classic ASP as I stick to ASP.NET MVC 5, but it looks to me as though you need very little of your VB logic in PHP. I recommend you use cURL as well and simply supply it with all the arguments you need to do the request, then work with the data you receive back. Don't forget to close the connection. <?php # create the header request, though as you've indicated it's using POST, this is probably unnecessary $request_headers = array(); $request_headers = 'Accept: application/x-www-form-urlencoded'; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, '[YourWebserviceUrlHere]'); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_POST, 0); curl_optopt($curl, CURLOPT_HTTPHEADER, $request_headers); $result = curl_exec($curl); curl_close($curl); # do with the $result value whatever you want here ?> Take a look through http://php.net/manual/en/function.curl-setopt.php for the various cURL options to use with PHP. And you might want to read a book on PHP before assuming that '$' before everything magically makes it PHP. Edited December 12, 2013 by captbeagle Quote Link to comment https://forums.phpfreaks.com/topic/284706-how-do-i-convert-this-to-php/#findComment-1462171 Share on other sites More sharing options...
.josh Posted December 12, 2013 Share Posted December 12, 2013 I'm not terribly versed in ASP either but based on his ASP code I think this one should be set to true: curl_setopt($curl, CURLOPT_POST, true); Quote Link to comment https://forums.phpfreaks.com/topic/284706-how-do-i-convert-this-to-php/#findComment-1462196 Share on other sites More sharing options...
sonnieboy Posted December 12, 2013 Author Share Posted December 12, 2013 Thank you good helpers. I am truly grateful for your assistance. captbeagle, your code did most of the heavy lifting and making that additional change by changing from 0 to true by Josh finally did the triack. The code is now doing almost exactly what the asp version was doing before. THANK YOU. Only strange thing is that my ajax used to return a message of "invalid user or password" if username and/or password is incorrect. That stopped working. I don't know if there is any relationship between the php file and ajax. Quote Link to comment https://forums.phpfreaks.com/topic/284706-how-do-i-convert-this-to-php/#findComment-1462222 Share on other sites More sharing options...
sonnieboy Posted December 12, 2013 Author Share Posted December 12, 2013 Sorry guys, my bad. I thought it was working. It isn't. I guess I needed to cache the page before testing. I will dig deeper. Thanks again. You are awesome. Quote Link to comment https://forums.phpfreaks.com/topic/284706-how-do-i-convert-this-to-php/#findComment-1462224 Share on other sites More sharing options...
.josh Posted December 12, 2013 Share Posted December 12, 2013 a lot of it depends on the server you are making the request to. If it has mechanisms in case to prevent bots, you may need to do things like fake user agent. Or if it's a secure (https) url, you'll need to set options that either handle or ignore SSL certificates and stuff. Look at the list of curl options from the link catbeagle supplied. You can also make use of curl_error() and curl_errno() to get some clues about what's going wrong. Quote Link to comment https://forums.phpfreaks.com/topic/284706-how-do-i-convert-this-to-php/#findComment-1462227 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.