-1

I use by PhantomJs for connect to my WebService and Post data to WebService's Function for special computing. But i can't get result from WebService's Function.

bin.js:

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();
});

webService.asmx:

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

I want something look like this in PhantomJs:

 $.ajax({
    type: "POST",
    url: 'http://127.0.0.1/Service.asmx/HelloWorld',
    data: {data: 'somethings'},
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function(data) {
        var result= data.d;
    }
});
  • 2
    Possible duplicate of [Get JSON page content with PhantomJS](http://stackoverflow.com/questions/8878839/get-json-page-content-with-phantomjs) – Artjom B. Feb 13 '16 at 08:08
  • 1
    @ArtjomB. I'm h.ganjyar (http://stackoverflow.com/questions/35267191/phantomjs-open-page-with-localstorage-by-default), I can't ask any question. I want to get returned data from WebService. –  Feb 13 '16 at 08:22
  • [I accidentally created two accounts; how do I merge them?](http://stackoverflow.com/help/merging-accounts) – Artjom B. Feb 13 '16 at 08:25
  • 1
    @ArtjomB. Tahnks, "Get JSON page content with PhantomJS" isn't my answer. I edited my Question. please that. –  Feb 13 '16 at 08:36
  • The answer says that you can access `page.plainText` to get the response. Have you tried it? What's the problem then? – Artjom B. Feb 13 '16 at 08:39
  • 1
    I tried it and result wasn't "Hello World". It was like : Stripped down page text: Service The following operations are supported. For a formal definition, please review the Service Description. HelloWorld This web service is using http://tempuri.org/ as its default namespace. Recommendation: Change the default namespace before the XML Web service is made public. Each XML Web..... –  Feb 13 '16 at 08:45
  • Are you sure that this endpoint supports POST requests? It doesn't seem to me that this question is about PhantomJS. – Artjom B. Feb 13 '16 at 08:46
  • 1
    I want by PhantomJs call a WebService and get returned Data. Who I do this? –  Feb 13 '16 at 08:51

2 Answers2

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
});
barbolo
  • 3,807
  • 1
  • 31
  • 31
0

I solved my problem with search about "phantomjs in c#".

My solution is use of NReco.PhantomJS library in c#.