Search code examples
phpasp-classic

equivalent of file_get_contents("php://input"); in classic asp


Is this it?

I am trying to convert, $data = file_get_contents("php://input"); to classic asp...

    Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP.6.0") 
    xmlhttp.open "GET", php://input, false 
    xmlhttp.setRequestHeader "Content-type", "application/x-www-form-urlencoded"
    xmlhttp.send
    TOKEN = xmlhttp.responseText    

edit: Answering John's question...

Realtime Updates

Following a successful subscription, Facebook will proceed to call your endpoint every time that there are changes (to the chosen fields or connections). For each update, it will make an HTTP POST request.

The request will have content type of application/json and the body will comprise a JSON-encoded string containing one or more changes.

Note for PHP developers: In PHP, to get the encoded data you would use the following code:

$data = file_get_contents("php://input"); $json = json_decode($data);


Solution

  • Edit #2

    This is an educated guess based on your Facebook info - try

    Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP.6.0") 
    xmlhttp.open "GET", Request, false 
    xmlhttp.setRequestHeader "Content-type", "application/json"
    xmlhttp.send
    TOKEN = xmlhttp.responseText
    

    Basically this is your original idea with a little change in line 2 and another in line 3. You could also try Request.Form rather than Request in line 2 as the script is receiving POST data

    Edit - yes, it looks like your code will work, with one minor change. Your URL needs to go inside double quotes - ie

    xmlhttp.open "GET", "php://input", false
    

    Thanks for the question. I've learned something today. I'll leave my original answer as background reading

    Could you tell me a bit more about what you are trying to achieve. It looks like you want to take the content of an external URL and then use it in your ASP page. You can certainly use an XML object provided that the output of your external URL is valid XML. The code looks like this.

    set xml = Server.CreateObject("Msxml2.DomDocument")
    xml.setProperty "ServerHTTPRequest", true
    xml.async = false
    xml.validateOnParse = false
    xml.load("http://yoururl")
    

    You then have an xml object, here just called "xml" which you can use however you need. For example if you just want it to appear in the page as is you would add

    Response.write xml
    

    If your external URL output is not valid XML then I don't think Classic ASP can't do this on its own, you may need to install a third party component on your server, such as AspTear

    http://www.alphasierrapapa.com/ComponentCenter/AspTear/

    The code you suggest above, or a variation on it, might well work, I'm going to experiment with it. Classic ASP itself has had no updates for more than a decade but Microsoft's XML processor certainly has been updated