Silverlight SecurityException while accessing php rest - php

im trying to access a php rest service on a different server with silverlight, but everytime i do the
request.EndGetResponse(ar) as HttpWebResponse;
it throws a SecurityException any idea how i can fix this?

Take a look at the URL Access Restrictions in Silverlight:
Also try adding the <allow-from http-request-headers="*"> statement in the clientaccesspolicy.xml on the php site.
When in doubt, run fiddler so you can see the exact sequence of web calls.

Related

Is it preferable to retrieve information directly from one site or through my web server using php?

I have an application that retrieves some info and give them to user from a certain public website. However, i am not sure whether i should let my app immediately connect to the target website or it should get the info through my web server using a simple PHP script (JSON).
Actually I am using Jsoup to get the information and I tried both and they worked perfectly ( immediate and PHP) using Jsoup. However, I have not published my app yet due to the confusion aforementioned.
Use the web service. If your client has logic to parse the HTML, it can break when the web page changes. The web service can absorb this change and make corrections, but your client cannot. Not unless you release another version of your app, and that can be a pain.

Using phonegap, is there a way for an Android device to communicate with PHP?

I have a php page which connects an API and gets information back which can then be displayed.
I'd like to turn this into an app for Android. I've heard of PhoneGap, which I know uses javascript, html, and css. I know javascript is capable of calling php files, but I am unsure how or if its even possible to call a php file from an android device. I'm not sure if android browsers can handle php, or what the deal is with them. So if you have any information on that, I'd appreciate it.
I'm also willing to rewrite the API call in javascript, but I don't think thats possible. If you think differently, please let me know what you're talking about.
Android cannot talk directly to PHP. What phonegap, javascript, etc.. are doing is simply issuing HTTP requests that happen to be handled by a PHP script.
The PHP code will execute, output some data (json, html, xml, gif, jpg, etc...) and send that out as a the HTTP request's reply.
PHP is just a server side language so it doesn't matter if your browser "can or cannot" handle it, only HTML is returned (unless you set a different content-type).
You may be worth while looking into REST style JSON api's which would allow a XMLRequest to be sent to. Have a look at this document
Theres also a nice tutorial here which shows how to call a REST API and a PHP Tutorial here to create a REST API.
1.It dosent matter to PhoneGap where the PHP is hosted or Its PHP OR ASP.NET OR ASP.NET MVC
2.If You wanna host your PHP code yourself in production (You mayb shouldn't do this in production). then you need a server and a static IP address
3.if you just wanna setup a PHP server for developmental purposes then just tie it to 127.0.0.1:81 and you can directly use this address it doesn't matter whether you have a static IP address or not.
I have done this with phonegap using jsonp
http://en.wikipedia.org/wiki/JSONP
Works great

How do I debug a webhook POST?

A webhook is sending me a POST, and I want to do some debugging on it. Currently I'm looping over the array and then sending a mail() to myself instead of printing (because how could I see what's printed to the page?), but I'm betting there's a more efficient way.
Any suggestions?
https://requestbin.com/ lets you create a temporary URL that will show you all the HTTP request data sent to it.
There are multiple options for debugging:
Use a debugger with an IDE, like netbeans. This will run the application and figure out where things are going wrong.
Use logfiles of your server, or generated by application exceptions
Collect your debug information with a buffer and put it in a file in your public directory. Overwrite with every new request.
I know this is quite an old question but if you want to see what kind of responses you are going to get from webhooks or you need to need to access the developer environment then there are a selection of tools that can help you.
RequestBin is probably one of the simplest to use by, providing a unique URL that you can then set this as your endpoint for Event notifications. Using this URL you can check to see what responses you are receiving.
You can generate a unique URL by creating a RequestBin.
An Example URL is this:
http://requestb.in/XXXXXXXX
This will be used to receive Event Notification Data and Receive Inbound Parse Data.
The results will then be found by heading to your RequestBin unique URL.
Ngork is also a tool that is useful for creating a local tunnel to your machine. This makes testing webhooks locally easy.
To setup install and enter the following in your CLI (after signing up first):
$ ngork 3000
This would open a connection to the port 3000 that is on your local machine, then at a URL you can put your URL for your PARSE Webhook or Event Webhook.
$ ngrok -subdomain=myappname 3000
Runscope is a tool for debugging APIs. It acts as a proxy, collecting all data sent to it and passes it on to another point. You may then, later, review what was sent to the API you’re debugging.
Source : https://sendgrid.com/docs/API_Reference/Webhooks/debug.html
http://httpresponder.com/ works also, and lets you configure a canned response if you need one.
You can use https://www.reliablewebhook.com/. They also have a plugin for Visual Studio Code for local debugging.

How to capture a website API traffic data with Google Analytics?

I have a website where most of the traffic comes from the API (http://untiny.com/api/). I use Google Analytics to collect traffic data, however, the statistics do not include the API traffic because I couldn't include the Google Analytics javascript code into the API pages, and including it will affect the API results. (example: http://untiny.com/api/1.0/extract/?url=tinyurl.com/123).
The solution might be executing the javascript using a javascript engine. I searched stackoverflow and found javascript engines/interpreters for Java and C, but I couldn't find one for PHP except an old one "J4P5" http://j4p5.sourceforge.net/index.php
The question: is using a javascript engine will solve the problem? or is there another why to include the API traffic to Google Analytics?
A simple problem with this in general is that any data you get could be very misleading.
A lot of the time it is probably other servers making calls to your server. When this is true the location of the server in no way represents to location of the people using it, the user agent will be fake, and you can't tell how many different individuals are actually using the service. There's no referrers and if there is they're probably fake... etc. Not many stats in this case are useful at all.
Perhaps make a PHP back end that logs IP and other header information, that's really all you can do to. You'll at least be able to track total calls to the API, and where they're made from (although again, probably from servers but you can tell which servers).
I spent ages researching this and finally found an open source project that seems perfect, though totally under the radar.
http://code.google.com/p/serversidegoogleanalytics/
Will report back on results.
you would likely have to emulate all http calls on the server side with whatever programming language you are using..... This will not give you information on who is using it though, unless untiny is providing client info through some kind of header.
if you want to include it purely for statistical purposes, you could try using curl (if using php) to access the gif file if you detect untiny on the server side
http://code.google.com/apis/analytics/docs/tracking/gaTrackingTroubleshooting.html#gifParameters
You can't easily do this as the Javascript based Google Analytics script will not be run by the end user (unless of course, they are including your API output exactly on their display to the end user: which would negate the need for a fully fledged API [you could just offer an iframable code], pose possible security risks and possibly run foul of browser cross-domain javascript checks).
Your best solution would be either to use server side analytics (such as Apache or IIS's server logs with Analog, Webalizer or Awstats) or - since the most information you would be getting from an API call would be useragent, request and IP address - just log that information in a database when the API is called.

Can't Consume Web Services

I've been trying to access Google Maps web services or even Yahoo Maps using PHP. When I run it, I get nothing. All the HTML and prints come out but absolutely nothing from Google service.
When I gave the code to my friend to run it on his local PC, it showed up fine and was working showing the map. But it seems I have trouble here at university.
Is it because I am behind a proxy? What could be the issue? Also the host can't be accessed outside the university.
Is there any solution to this?
If it is getting stuck on simplexml_load_file, and you are trying to use simplexml_load_file to get a remote file, and your University (like mine) has PHP in safe mode, this will fail. You can't get remote files like that in safe-mode. You should get the XML via cURL, and then use simplexml_load_string.
This would also explain why your friend could do it and you couldn't.

Categories