PhantomJs-致电WebService&从中获取数据

时间:2016-02-13 08:05:17

标签: web-services phantomjs

我使用PhantomJs连接到我的WebService,发布数据用于<​​em> WebService的功能以进行特殊计算。但我无法从 WebService的功能中获得结果。

bin.js:

import zipfile
from threading import Thread

def chunks(l, n):
    """Yield successive n-sized chunks from l."""
    for i in xrange(0, len(l), n):
        yield l[i:i+n]

def extractFile(zFile, passwords):
    for password in passwords:
        try:
            zFile.extractall(pwd=password)
            print '[+] Found password ' + password + '\n'
            sys.exit(0)
        except:
            continue

def main():
    zFile = zipfile.ZipFile('evil.zip')
    with open('dictionary.txt', 'rb') as pass_file:
        passwords = [i.strip() for i in pass_file]
    passes = list(chunks(passwords, 10))
    for pas in passes:
        t = Thread(target=extractFile, args=(zFile, pas))
        t.start()

if __name__ == '__main__':
    main()

webService.asmx:

var page = require('webpage').create();

var data = {
    'str': 'sample string'
};
page.open('http://127.0.0.1/Service.asmx/HelloWorld', 'POST', data, function(status) {
    // Get status
    console.log('Status: ' + status);
    // I want to get result
    phantom.exit();
});
  

我想在PhantomJs中看到这样的东西:

[WebMethod]
public string HelloWorld(string str)
{
  return str;
}

2 个答案:

答案 0 :(得分:1)

var webPage = require('webpage');
var page = webPage.create();
var postBody = 'param1=value1&param2=value2';

page.open('http:www.myservice.com/service', 'POST', postBody, function(status) {
  console.log('Status: ' + status);
  console.log('HTML Content: ' + page.content); // in case of an HTML response
  console.log('JSON: ' + JSON.parse(page.plainText)); // in case of a JSON response
});

答案 1 :(得分:0)

我通过在c#&#34;中搜索&#34; phantomjs解决了我的问题。

我的解决方案是在c#中使用NReco.PhantomJS库。