php - how to make a proxy for a web service

2019-09-03 04:47发布

问题:

I'm trying to get around an access control origin error for a web service by building a local proxy, but I'm not sure how to do it. The web service looks like the attached file, and is accessed directly by using the following URL:

https://url.com/SparkService.asmx?op=InsertConsumer

How would I write something locally that carried out this URL's functionality?

I built a PHP file that will pull the web service URLs contents, but it doesn't seem to carry out the functionality of that web service:

<?php
    $op = htmlspecialchars($_GET["op"]);
    $proxyURL = 'https://url.com/SparkService.asmx?op=' . $op;
    die( file_get_contents($proxyURL) );
?>

回答1:

The image shows you have to use a POST, which you can't do with bare-bones file_get_contents - it defaults to using a GET query. You'll have to use CURL, or set up a stream to configure and perform a POST.



回答2:

I am not sure about your intension of doing this.

you can use WSO2 ESB proxy[1] to send messages to the real service through a local end point. Or else you can create your own service by using WSO2 AS[2] and deploying a sample POJO as a web service.

[1] http://wso2.org/project/esb/java/4.0.0/docs/samples/proxy_samples.html [2] http://wso2.org/project/app-server/