javascript - CasperJS/PhantomJS - Browsing one page and send HTTP request to other resource -
i need browse 1 page, retrieve data , send data service via http requests. far know, casperjs/phantomjs can work simultaneously 1 web resource. how bypass limitation?
upd: need make request casperjs/phantomjs side, not page context through evaluate()
.
@interloper - able perform integration, need 2 basic requirements:
1 - page requested, must habilidada receive information via http access control (cors). depend on type of application! example, if using c # in project, you'll have add following code in web.config in system.webserver
:
<httpprotocol> <customheaders> <add name="access-control-allow-origin" value="*" /> <add name="access-control-allow-headers" value="content-type" /> </customheaders> </httpprotocol>
with this, project / page enabled can make access / exchange of information other domain ...
2 - can call url domain, , in our case, code casperjs, can perform http call using ajax (jquery / js), following example:
function get_response(output) { $.ajax({ type: "post", url: "url", datatype: "text", async: false, data: { param1:value1 }, success: function (response) { var $doc = $.parsexml(response); output($($doc).find('tagsxml').find('tag_response1')[0].textcontent + '|' + $($doc).find('tagsxml').find('tag_response2')[0].textcontent); }, error: function (response) { output(''); } }); } get_response(function (output) { test.pass('output: ' + output); var value1 = output.split('|')[0]; var value2 = output.split('|')[1].replace(/\n/g, ""); });
with code, can perform "remote access" , feedback information (if necessary)
Comments
Post a Comment