soapclient or fopen not working - soap-client

I'm trying to set up a PHP SoapClient to connect to a wsdl...
CURL & WGET from the server work fine.
If I try to use soapclient I receive the error messages below.
$wsdl = 'http://pav3.cdyne.com/PavService.svc?wsdl';
try {
$client = new SoapClient($wsdl, array('trace' => true, 'exceptions' => true));
} catch (SoapFault $f) {
echo $client->_getLastRequest();
echo $client->_getLastResponse();
echo $f->getMessage();
} catch (Exception $e) {
echo $client->_getLastRequest();
echo $client->_getLastResponse();
echo $e->getMessage();
}
I get the error message:
<br /><b>Warning</b>: SoapClient::SoapClient(http://pav3.cdyne.com/PavService.svc?wsdl) [<a href='soapclient.soapclient'>soapclient.soapclient</a>]: failed to open stream: HTTP request failed! in <b>/coachflex/www/htdocs/CoachFlex/modules/other/checkAddress.php</b> on line <b>35</b><br />
<br /><b>Warning</b>: SoapClient::SoapClient() [<a href='soapclient.soapclient'>soapclient.soapclient</a>]: I/O warning : failed to load external entity "http://pav3.cdyne.com/PavService.svc?wsdl" in <b>/coachflex/www/htdocs/CoachFlex/modules/other/checkAddress.php</b> on line <b>35</b><br />
If i try to simply use fopen on the above address, I get:
Warning: fopen(http://pav3.cdyne.com/PavService.svc?wsdl) [function.fopen]: failed to open stream: HTTP request failed! in /coachflex/www/htdocs/CoachFlex/modules/other/checkAddress.php on line 37
I just cannot figure out why I can connect via curl/wget, but not through PHP. allow_url_fopen is set to On

I solved my problem. It was actually an issue with my firewall. The firewall was dropping packets sent via PHP, but via curl or wget were not being dropped. I added a rule for all traffic from that server and increased the packet drop length and everything is working great now!
This page was what pointed me in the right direction: http://www.radiotope.com/content/safari-and-sonicwall

Related

chrome.devtools.inspectedWindow of chrome request getContnet cann't get the content

I wrote a chrome extension for test devetools .But I couldn't get the content of the request.
The followiing is my code:
chrome.devtools.network.onRequestFinished.addListener(
function(request) {
if(request.request.url==='https://www.google.com/'){
request.getContent((content,encoding)=>{
chrome.devtools.inspectedWindow.eval(
'console.log("url address: " + unescape("' +
escape(request.request.url) + '"))');
chrome.devtools.inspectedWindow.eval('console.log("content:'+ content+' ")');
chrome.devtools.inspectedWindow.eval('console.log("start console log content: ")');
chrome.devtools.inspectedWindow.eval('console.log("encoding:'+encoding+' ")');
chrome.devtools.inspectedWindow.eval('console.log("end console log content:")');
});
}
}
);
chrome.devtools.panels.create('Osudio', null, 'panel.html', null);
The following is my screenhot. (We can see the content can be inspected in the watch)
I think this problem is affected by the "potentially encoded" .
I hope someone can help me .I'm already crazy.

Issue while addding files in IPFS server having cloudflare enabled

I have a ubuntu server having cloudflare enabled in it. I have set up the nginx for reverse proxy, I have defined the ports and done IPFS setup.
While adding the file on the server I am getting the error that says:
Unexpected token < in JSON at position 0
I am creating a buffer of a file and adding the data using ipfs.files.add function.
Here is the code snippet:
let testBuffer = new Buffer(testFile);
ipfs.files.add(testBuffer, function (err, file) {
if (err) {
console.log(err);
res.send(responseGenerator.getResponse(500, "Failed to process your request!!!", []));
}
console.log(file)
}
Kindly help with the solution.
Thanks.

CURL - NodeJS Rest API call Imperva - [SyntaxError: Unexpected token <]

I have written a shell script code which is successfully adding a new OS Connection IP in Imperva system/instance.
## Create a new IP OS connection in a given site, server group.
create_ip()
{
JSESSIONID="${1}"
addThisIP="${2}"
siteName="${3}"
serverGroupName="${4}"
echo -e "\n- Trying to create a new OS connection IP now.\n";
##Make sure while initiating a REST API call, any parameter which has ' ' (space) in Imperva should be substituted with '%20'.
##JSESSIONID will be generated first and will be available to this function
create_new_ip_output="$(curl -ik -X POST -H "Cookie: JSESSIONID=$JSESSIONID" -H "Content-Type: application/json" -H "Accept: application/json" "https://${MX}:8083/SecureSphere/api/v1/conf/serverGroups/${siteName// /%20}/${serverGroupName// /%20}/servers/${addThisIP}" -d '{"connection-mode":"SSH","host-name":"thisLinuxServer.fdqn","OS-type":"linux","user-name":"enter_your_userID"}')";
return_code="$?";
if [[ "${return_code}" == "0" && ! `echo "${create_new_ip_output}" | grep "do not have permission"` ]]; then
echo -e "\n\n- OS connection IP (${addThisIP}) created successfully in site: ${siteName}, servergroup: ${serverGroupName} and stdout:\n${create_new_ip_output}\n";
return 0;
else
echo -e "\n\n- Failed to create a new OS connection IP (${addThisIP}) in site: ${siteName} and servergroup: ${serverGroupName}\n- using session ID: ${JSESSIONID}, error log:\n${create_new_ip_output}\n";
return 1;
fi
}
OK, the above code works fine and once run, I see valid output showing whether an IP got added successfully or what was the failure message.
Now, I'm trying to implement the same functionality in NodeJS.
To do that, I have successfully created functions to generate JSESSIONID (so that I can use it to perform multiple REST/API call operations, rather than creating a new session each time for any operation), successfully deleting a JSESSIONID (i.e. to logoff/out from Imperva session so that I don't hit the limit) and to successfully search an IP in Imperva system if it has been previously added.
Using the above shell script logic, I have written the following NodeJS code to add a new OS Connection IP in Imperva using Rest/API, but I'm getting an error.
//Imperva create IP
//qData is a hash array that has valid index/value pair values.
var impervaCreateIP = function(qData){
var deferred = Q.defer();
var data = ''
var options = {
hostname: 'myImpervaServerInstance.mycompanydomain.com',
port: 8083,
method: 'POST',
path: '/SecureSphere/api/v1/conf/serverGroups/'+ qData['siteName'] + '/' + qData['serverGroupName'] + '/servers/' + qData['ip'],
headers: {
'Content-Type': 'application/xml',
'X-Requested-With': 'Nodejs',
'Cookie': 'JSESSIONID='+qData['sid']
}
}
//svtLog() is a logger that I'm using to log messages to a file. Out of scope of this post.
svtLog('info','Imperva','Inside impervaCreateIP function')
svtLog('info','Imperva',qData['ip'])
svtLog('info','Imperva',qData['siteName'])
svtLog('info','Imperva',qData['serverGroupName'])
svtLog('info','Imperva','')
console.log('Inside impervaCreateIP')
console.log(options);
httpHelp(options, data)
.then(function(fullResponse){
var result = JSON.parse(fullResponse[1])
console.log("11 -----")
console.log(result)
console.log("22 -----")
deferred.resolve(qData['sid'])
console.log(result)
})
.fail(function(e){
svtLog('error','Imperva','Failed to add IP in Imperva')
svtLog('info','Imperva',qData['ip'])
svtLog('error','Imperva',e)
svtLog('info','Imperva','')
deferred.reject(e)
})
return deferred.promise;
}
Error message:
Inside impervaCreateIP
{ hostname: 'myImpervaServerInstance.mycompanydomain.com',
port: 8083,
method: 'POST',
path: '/SecureSphere/api/v1/conf/serverGroups/some%20Site%20NameInImperva/someServerGroupNameInImperva_01/servers/10.20.30.40',
headers:
{ 'Content-Type': 'application/xml',
'X-Requested-With': 'Nodejs',
Cookie: 'JSESSIONID=7B3C378D365B673F6C749847DEDC7D8F } }
[SyntaxError: Unexpected token <]
I'm looking for 2 things:
1. How to resolve the error (as shown above).
2. How to pass CURL's -d option {...} body parameters in the NodeJS code above, like I used it in the shell script.
PS: Changing POST to GET (method), assures that the code is fine syntax wise as it successfully shows the IP (with GET operation) with the above NodeJS code.
So, it's failing only when I use POST (i.e. when I'm trying to create an IP) -vs- GET (which I use to find an IP exist or not). I checked as per the Imperva API doc, the response comes in JSON format. Not sure if due to missing bullet# 2 question, I'm getting this Syntax error with POST.
OK.
Solution to both bullet# 1 and #2 was to set the CURL "-d option values" in NodeJS like shown below (I was setting it blank earlier):
var data = '{"connection-mode":"SSH","host-name":"thisLinuxServer.fdqn","OS-type":"linux","user-name":"enter_your_userID"}'
Now, both options and data will be sent to httpHelp(options,data) and it'll work.
The above is just an dummy data value. Usually I'd pass valid host-name in the JSON object.
Never thought that not setting the data variable would result in this syntax error.
Other thing, I was missing BIG time was the value for 'Content-Type' inside headers variable. That was the reason, the error message was having "<" bracket in it (as by default it looks for a <body>...</body> section containing some XML format but in our case, the HTML response contained or was getting returned in JSON { ... } format way for the body section. That's why it was showing an error for unexpected token <.
As per the API doc, it should have been "JSON" type, thus changed that line to
'Content-Type': 'application/json',

Error: Unable to reach host: "api.twilio.com"

I'm using node-twilio and I keep getting a "Error: Unable to reach host: "api.twilio.com" for every request. We've checked the packets via mtr and they are reaching api.twilio.com. Running on debian on GCE.
After days of digging around, found out that the node-twilio module shows many errors incorrectly as:
"Error: Unable to reach host: "api.twilio.com".
The following lines:
var error = null;
if (err || (response && (response.statusCode < 200 || response.statusCode > 206))) {
error = {};
// response is null if server is unreachable
if (response) {
error.status = response.statusCode;
error.message = data ? data.message : 'Unable to complete HTTP request';
error.code = data && data.code;
error.moreInfo = data && data.more_info;
} else {
error.status = err.code;
error.message = 'Unable to reach host: "'+client.host+'"';
}
}
This happens because you have a self signed certificate in your chain and the underlying module twilio depends on is request, which is throwing the following error:
Error: SELF_SIGNED_CERT_IN_CHAIN but this is not the error being thrown by node-twilio (bad error propagation on their part)
There are 2 fixes:
1.Tell nodejs to ignore self signed certificates in chain by setting:
export NODE_TLS_REJECT_UNAUTHORIZED=0
Find the self signed certificate and remove it from the chain. Here is an example using openssl: https://serverfault.com/questions/590870/how-to-view-all-ssl-certificates-in-a-bundle
References:
https://github.com/request/request
https://github.com/twilio/twilio-node/blob/45858420688854494c2ed476a1997773c33a32a0/lib/Client.js
Ignore invalid self-signed ssl certificate in node.js with https.request?
It may be because of your internet connection.
After couple of minutes, if you have internet, try again and it should work.

Status read failed in LWP Useragent

Case 1:
My server (accessing remotely does not have internet access) having the connectivity to the remote server in 443 port. Using web service URL, I need to send the web service request and receive the response. I am able to send the request using but unable to receive the response from remote server.
code:
Here is my code which i am using to send and receive the https request using the lwp agent in perl
use Data::Dumper;
use LWP::UserAgent;
use HTTP::Status;
use HTTP::Response;
use HTTP::Request::Common;
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;
$LWPUserAgent = new LWP::UserAgent( 'timeout' => '20');
$LWPUserAgent->ssl_opts('verify_hostname' => 0) ;
$WEB_URL="https://webserviceurl.com/Request?Arg1|Arg2|Arg3|Arg4";
$Response = $LWPUserAgent->get($WEB_URL);
print Dumper $Response ;
I printed the response using Data::Dumper and getting below response.
$VAR1 = bless( {
'_content' => 'Status read failed: at /usr/share/perl5/Net/HTTP/Methods.pm line 269.',
'_rc' => 500,
'_headers' => bless( {
'client-warning' => 'Internal response',
'client-date' => 'Tue, 13 Oct 2015 15:13:21 GMT',
'content-type' => 'text/plain'
}, 'HTTP::Headers' ),
'_msg' => 'Status read failed: ',
'_request' => bless( {
'_content' => '',
'_uri' => bless( do{\(my $o = 'https://webserviceurl.com/Request?Arg1%7Arg2%7Arg3%7Arg4')}, 'URI::https' ),
'_headers' => bless( {
'user-agent' => 'libwww-perl/6.04'
}, 'HTTP::Headers' ),
'_method' => 'GET'
}, 'HTTP::Request' )
}, 'HTTP::Response' );
I searched more about this in google and i am unable to found any idea about this.
My server information are :
OS - wheezy 7.2 64bit.
perl 5, version 14, subversion 2 (v5.14.2) built for x86_64-linux-gnu-thread-multi
LWP::UserAgent - 6.04
HTTP::Response,HTTP::Status,HTTP::Request::Common versions are - 6.03.
Case 2: My server (in home and internet access) having the connectivity using my static ip of the internet connection. Using my proxy trying to run the above code with below piece of code.
$LWPUserAgent->proxy('https', 'http://192.168.12.10:3128') ;
I am able to send and receive the https requests using LWP agent and working fine.
My server information are:
OS - squeeze (6.0.6) 32 bit
perl, v5.10.1 (*) built for i486-linux-gnu-thread-multi
LWP::UserAgent - 6.13
HTTP::Response - 5.836
HTTP::Status - 5.817
HTTP::Request::Common - 5.824
I confused of the these things.
1.OS problem
2.Package versions problem
3.whether is it a bug in wheezy
If any one can provide me the correct direction to resolve this it would be highly appreciated.
Please set $ENV{HTTPS_DEBUG} = 1; and write here what the script prints.

Resources