twilio bhrowser to browser call issue? - php

I am following http://www.twilio.com/docs/quickstart/client/browser-to-browser-calls for making a call from browser to browse.
According to documentation open two browser with:
http://127.0.0.1/client.php?client=test1 and 127.0.0.1/client.php?client=test2
When I am using sandbox APP ID:
The both browser couldn't able to connect but it a call connect to the the sandbox number.
When I am using my app ID:
It shows me the following error:
Component: TwiML errors
httpResponse: 502
ErrorCode: 11200
url: http://127.0.0.1/demo.php
Request: What Twilio sent your server
HTTP Method: GET
HTTP URL: http://127.0.0.1/demo.php
HTTP BODY: Key Value
AccountSid xxxxxxxxxxxxxxxxxxxxxxxxx
ApplicationSid dddddddddddddddddddddddddd
Caller client:jenny
CallStatus ringing
Called
To
PhoneNumber tommy
CallSid cccccccccccccccccccccccccccc
From client:jenny
Direction inbound
ApiVersion 2010-04-01
Response: What your web application responded with to Twilio
HTTP Headers: Key Value
Date Thu, 25 Aug 2011 11:36:22 GMT
Content-Length 137
Connection close
Content-Type text/html
Server TwilioProxy/0.7
with <html><head><title>502 Bad Gateway</title></head>
<body><h1>Bad Gateway</h1>An upstream server returned an invalid response.</body></html>

The VoiceURL assigned to your application must be a publicly-accessible URL so that the Twilio servers can reach it. If it's running only 127.0.0.1 that is only accessible from your local machine and we can't reach it.
You may be interested in something like localtunnel.com or ngrok which will let you expose your local server to the public.

Related

PHP web service for command line users

I have been given a task to write a web service to push data from sensors to the server database.
I have written a PHP webservice which takes some arguments in GET, process the data in it and stores the data in the database.
Example
http://www.example.com/pushDataService/index.php?arg1=<Data 1>&arg2=<Data 2>&arg3=<Data 3>
But our firmware programmer wants something that he can test on a command line.
Just like SMTP communication using telnet
Example
Telnet mail.example.com 25
EHLO mail.example.com
AUTH LOGIN
UserName encrypted in base 64
Password encrypted in base 64
MAIL FROM:<test#example.com>
RCPT TO:<test#domain.com>
DATA this is a test message.
Can I make the webservice work like this where he can do the handshaking process in command line and then each argument is sent individually and user get a response for each argument ?
Please help, I am new to PHP and have no idea of (web) service like this!
Thank you
Edit:
We are already using MQTT to push the data to the server but we need another server to push data which will work as a combination of SMTP mail server and MQTT protocol...
Will a SOAP web service do the job for me?
The http://www.example.com/pushDataService/index.php?arg1=<Data 1>&arg2=<Data 2>&arg3=<Data 3> request can be done Just like SMTP communication using telnet as following:
Telnet www.example.com 80
GET /pushDataService/index.php?arg1=<Data 1>&arg2=<Data 2>&arg3=<Data 3> HTTP/1.1
Host: www.example.com
<CR>
<CR>
Pushing data with GET requests is not the best idea. PUT or POST requests would be more suitable. First of all it is not idempotent and should never be cached, and what is more important - it is way more flexible in data format and size. The POST request sending json data may look like
Telnet www.example.com 80
POST /pushDataService/index.php HTTP/1.1
Host: www.example.com
Content-Type: application/json; charset=utf-8
Content-Length: 57
{"arg1":"<Data 1>", "arg2":"<Data 2>", "arg3":"<Data 3>"}

Post request missing payload

I'm building an api that receives incoming webhooks from external parties. Post requests to my application lack a body in some cases. In my logs I see the incoming request with the following header:
Accept: */*
Content-Length:
Content-Type: application/json
As you can see the content-length is empty.
I cannot reproduce the problem. What I've tried thus far:
The request payload is only missing coming from a specific third party. If however, I provide this third party with a different callback url like request bin, the payload is not missing.
Connected this party source to our test environment. Which has exactly the same configuration (checked the entire php.ini) and the same version of our software. On our test server, requests are received with payload.
When sending post requests with Postman to our production environment, webhooks are received with payload.
Both test and production are https. I've tried sending http requests to our production server to see what happens, and I get an error as expected and no received headers in our logs.
Checked the php post_max_size, which is on 24M.
When creating a callback.php file in my public folder, and have the third party send it's webhooks to this destination, I am able to write the results to a log with the following code, which includes a payload. If I to output php://input later on in my Laravel application, it doesn't work:
$postdata = file_get_contents("php://input");
$file = fopen("webhook.log","w");
echo fwrite($file,$postdata);
fclose($file);
Both servers are running on the same php version (php7), and I am at a loss as to what to try next.
Found it! The problem was a port 80 to 443 redirect in a vhost configuration. I earlier dismissed redirects - which seem to be a common source of missing payloads in post requests - as possible cause; I had made a test script which succesfully received payloads on this very same server.
However, I had placed this test script in the servers public folder, which was not subject to the same redirects as was the root of my application. After removing the redirect, payloads where received as expected.

Connection with API - redux

I'm building a project with react and redux, but I can't connect with my API.
I have this,
componentDidMount() {
const {dispatch} = this.props;
dispatch(fetchByQuerystring());
}
and fetchByQuerystring is:
export function fetchByQuerystring() {
return function(dispatch) {
return fetch(`http://my_domain.dev/api`)
.then(response => response.json())
.then(json => dispatch(receiveByQuerystring(json)));
}
}
When I run it, I get this error:
Fetch API cannot load http://my-domain.dev/api. No
'Access-Control-Allow-Origin' header is present on the requested
resource. Origin 'http://localhost:3000' is therefore not allowed
access. If an opaque response serves your needs, set the request's
mode to 'no-cors' to fetch the resource with CORS disabled.
How can I solve this problem?
When you are on a site A and call (with ajax requests) a different server B (different port, different domain name / ip address or different protocol), the browser expects B to explicitly allow A.
This is done with HTTP reponse headers added by the server B (and OPTIONS support), see CORS (Cross-Origin Resource Sharing).
If you must be able to call your API from other servers in production, adding CORS support in laravel is a good idea. Don't add them if you don't need them.
If your API calls are simple enough and don't require cookies, you can configure your local Apache to just add the header Access-Control-Allow-Origin: *.
Otherwise, you should serve both resources (API and react frontend) from the same origin.
You would need to set CORS headers on your local webserver that runs http:/my-domain.dev/api
Headers to send: Access-Control-Allow-Origin: http://my-domain.dev/api
This may help for Laravel github.com/barryvdh/laravel-cors

What does X-Backside-Transport Header do?

I have come across this header for the first time and not sure what it does or mean. I have searched around and couldn't find what I was looking for.
I am trying to consume a SOAP API using PHP SoapClient class and it's returning an empty response and these response headers. Also, no exception is thrown.
HTTP/1.1 200 OK
X-Backside-Transport: FAIL FAIL,FAIL FAIL
Connection: close
Transfer-Encoding: chunked
Content-Type: text/xml
Date: Tue, 21 Jun 2016 20:09:50 GMT
X-Client-IP: xx.xxx.xxx.xxx
Any help is appreciated.
It seems that the web service you're trying to communicate is behind the xml firewall (probably IBM DataPower, it does send X-Backside-Transport header on failere) and blocks the error response (aka. fault message). This is the default behaviour for the xml firewalls. Root cause can be malformed soap message (i.e.: wrong data type) or an server site exception.
In order to solve the problem, you should contact with the web service owner.
I've seen this in the past when communicating with IBM Backends, in my experience it has also been joined with a HTTP 401 Unauthorised.
The reason for the error on my side was because of duplicate headers (e.g. sending the same head twice...)
Hope this helps.

error while using PHP Outlook Web Access: Access Microsoft Exchange Web services via OWA API

I am using PHP Outlook Web Access: Access Microsoft Exchange Web services via OWA API for the sole purpose of accessing user's calendar appointment.Everything is working just fine for all user but for one specific user it's showing error as:
Message: Use of undefined constant _DEBUG_ - assumed '_DEBUG_'
Filename: classes/connection.php
Line Number: 51
There was a problem parsing your XML!
New http() object instantiated.
--------------------------------
fetch() called
url: https://exchange.icimod.org/Exchange/spandey/calendar/
getFromUrl() called
Authentication will be attempted
XML request will be sent
HTTP/1.1 302 Object Moved
Content-Length: 179
Content-Type: text/html
Location: https://exchange-1.icimod.org/Exchange/spandey/calendar/
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
Date: Tue, 08 Oct 2013 05:12:21 GMT
Connection: close
Object Moved
This document may be found here
New xml() object instantiated.
fetch() called.
XML error: Invalid document end at line 2
Select *
FROM Scope('SHALLOW TRAVERSAL OF "/Exchange/spandey/calendar/"')
WHERE NOT "urn:schemas:calendar:instancetype" = 1
AND "DAV:contentclass" = 'urn:content-classes:appointment'
ORDER BY "urn:schemas:calendar:dtstart" ASC
In here link it gives the link of outlook express. Why is it so? Is it the problem of configuration or am I doing something wrong?
Any help/suggestion is welcome.Thanks in advance.
Guys found the problem area, Problem is user is stored in 2 seperate exchange account and I am using only one and not the other.

Categories