leesiulung Posted April 19, 2007 Share Posted April 19, 2007 Basically, I'm writing my own proxy for AJAX using the XMLHttpRequest object. My problem is with an asynchronous call as follows: if(XMLHttpRequestObject.overrideMimeType) XMLHttpRequestObject.overrideMimeType('text/xml'); url = 'proxy.php?proxy_url=' + escape('http://www.google.com'); XMLHttpRequestObject.open('POST', url, true); XMLHttpRequestObject.setRequestHeader('Content-Type', 'text/xml'); XMLHttpRequestObject.setRequestHeader('SOAPAction', '""'); XMLHttpRequestObject.onreadystatechange = getResults; XMLHttpRequestObject.send(....) The problem I have is that the proxy.php page is not able to retrieve the information being sent in the $_POST array. Where should this data be? Since the XMLHttpRequestObject does not name the data like a regular POST from a form with fields.... How can I retrieve this data? Any help would be much appreciated as I spent many days on this problem. Note, this problem stem from an earlier post that asked a different question. Basically I had to create my own proxy script since the original ones I used did not supply the correct information to the server in the header etc... I can't seem to edit my posts. Is there an edit button I missed? Other thread here edit: found the edit button. Quote Link to comment Share on other sites More sharing options...
Glyde Posted April 19, 2007 Share Posted April 19, 2007 When posting data, content-type must be application/x-www-form-urlencoded, otherwise the server won't parse the post body. Quote Link to comment Share on other sites More sharing options...
leesiulung Posted April 19, 2007 Author Share Posted April 19, 2007 Problem is the given code works without the proxy. With the proxy in place it will not work. Is there any way to get the data with content-type be text/xml? Quote Link to comment Share on other sites More sharing options...
Glyde Posted April 19, 2007 Share Posted April 19, 2007 Well now I'm really confused. You're trying to connect through a proxy to google.com? But, why do you need to submit the data to the proxy as text/xml? Quote Link to comment Share on other sites More sharing options...
leesiulung Posted April 19, 2007 Author Share Posted April 19, 2007 Sorry, that url just happens to be there as I was typing it in. I will try to be clearer next time. The correct url is 'http://services.xmethods.net/soap'. I'm trying to send a soap envelope, but with the content-type set at text/xml the proxy.php page does not receive the POSTED data sent by the XMLHttpRequestObject. I will edit the code in original post to reflect this. edit: actually I can't edit the original post as there is no such option on the page. Quote Link to comment Share on other sites More sharing options...
Glyde Posted April 19, 2007 Share Posted April 19, 2007 You don't need to post as text/xml though, as I don't believe it's required. However, if it is in fact needed, what you should do is post it as application/x-www-form-urlencoded to the PHP script, then have a POSTBODY attribute such as: contenttype=text/xml&therestofyourdata, then when the proxy connects to the SOAP server, it sends it as text/xml. But again, at least in Apache/PHP as far as I know, unless the content-type is application/x-www-form-urlencoded, data will not be picked up. Quote Link to comment Share on other sites More sharing options...
leesiulung Posted April 19, 2007 Author Share Posted April 19, 2007 Tricky situation, but I actually need the AJAX call to set the header to 'text/xml' before the PHP script. Is there a way around this? Quote Link to comment Share on other sites More sharing options...
Glyde Posted April 19, 2007 Share Posted April 19, 2007 Try reading $GLOBALS['HTTP_RAW_POST_DATA']. You'll also have to make sure always_populate_raw_post_data is enabled in php.ini Quote Link to comment Share on other sites More sharing options...
leesiulung Posted April 19, 2007 Author Share Posted April 19, 2007 You are a genius!!! The data is right there.... Thank you so much!!! Quote Link to comment Share on other sites More sharing options...
leesiulung Posted April 19, 2007 Author Share Posted April 19, 2007 Oddly enough my ;always_populate_raw_post_data = On is commented out in my php.ini residing in C:\Windows folder is commented out, yet it works. Quote Link to comment 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.