How to get mobile device data from a http request? - c#

I've built a web api that is called via an application (iOS/Android) through HTTP requests. I'm trying to implement a GET request that returns different data based on the device, OS, application version, .. etc. I've been using UserAgent with IOS devices and it's working just fine, it goes like that:
var uaParser = Parser.GetDefault();
var clientInfo = uaParser.Parse(Request.Headers.UserAgent.ToString());
Also if I opened the request via browser it also returns the data. Example of the response is: UserAgent: Windows 10 Other Chrome 63.0.3239
The problem is in the Android devices, it doesn't send any data about neither the device nor the OS, and I don't want to hard code the details in the android apps, I believe they are sent somewhere as Crashlytics can show these details for both iOS and Android.
Is there is any possible solution to get this data from the requests itself?

If you really wana do that then you could programically get android device name and its version and send it to your server as a parameter in http request...
To get Device Name
String devName = android.os.Build.MODEL;
To get Version code
String androidOS = Build.VERSION.RELEASE;
Then You Could Easily Send Them To Your Server As A Parameter In Your Request And Store Them To Database etc....Hope This Helps ! Cheers !

Related

ZKTeco Push SDK

i'm new to ZKteco devices! I am using a Zkteco device. I have a Zkteco Device and I have downloaded a standalone SDK, but this SDK doesn't trigger the events, (for example OnVerify, or OnAttTransaction).
So, I read in some articles, that I need to use Push SDk, but I can't find it.
I took one month to find that for that PUSH SDK and ADMS, clearly ZKTeco is not open to share that. so I had try to proceed otherwise. Here is the solution I had implement and it work properly.
The push SDK is just HTTP request made by ZKTeco device to the Bioserver.
You can use a tool like Wireshark to scan HTTP requests made by your device and implement same request/response on your own server.
For exemple, the ZKTeco device model MB560-VL send requests like this one
GET http://[SERVER-IP:PORT]/iclock/getrequest?SN=XXXXXXXXXX
and if like the BioTime software, your server just send
OK
as response in text/plain, your device will view your server as a "BioTime"
Note that your ZkTeco Device should have ADMS support, so that you will first configure SERVER-IP and PORT on the device (see your official device documentation on ZKTeco website)
User registration
When a user is registered on the device, the device send this request
POST /iclock/cdata?SN=XXXXXXXXXX&table=OPERLOG&Stamp=9999
with user information on the HTTP buffer. something like this one
PIN=2\tName=Johny Deep\tPri=0\tPasswd=\tCard=\tGrp=1\tTZ=0000000100000000\tVerify=0\tViceCard=\tStartDatetime=0\tEndDatetime=0\n
your server should just parse this data and respond OK to this request
User logs (clock_in / clock_out) Device request
POST /iclock/cdata?SN=XXXXXXXXXX&table=ATTLOG&Stamp=9999
the data sent by device on HTTP data buffer looks like
2\t2022-07-12 16:00:20\t1\t15\t\t0\t0\t\t\t43\n
As you can see you parse this string with '\t' as the separator of informations
the first integer is the User-PIN,
the second part is the date and time,
the third part is clock-in if value==0 and clock-out if value==1
Here is an exemple of implementation with Python
#http.route('/iclock/getrequest', type='http', auth="public", csrf=False)
def zk_bio_device_ping(request):
print("----------DEVICE PING-----------")
print(request.GET)
return HttpResponse("OK", content_type='text/plain')
#http.route('/iclock/getrequest', type='http', auth="public", csrf=False)
def zk_bio_device_push(request):
print("----------DEVICE SEND DATA----------")
print(request.GET)
print(request.body.decode('utf-8'))
return HttpResponse("OK", content_type='text/plain')
Device do not use any authentification to communicate with server ! I'm pretty sure that's a big security issue.

Azure Cloud Messaging - Message Processor application gets Exception

I am trying a Cloud application using Raspberry Pi 3 with Windows 10 IOT Core.
I have already completed a Universal App which collects data and messages it to the cloud, which is functional.
Next, I try to write a little Application to receive these messages from Azure using the Message Bus.
I have registered my device in Azure (trial version) and got some connection strings and Ids. I use this same connection string to connect to the event message service:
string IotHubUri = "HostName=<My>Hub.azure-devices.net;DeviceId=<MyRaspiPC>;SharedAccessKeyName=iothubowner;SharedAccessKey=<The primary key>"
string iotHubD2cEndpoint = "messages/events";
EventHubClient client = EventHubClient.CreateFromConnectionString(
IotHubUri,
iotHubD2cEndpoint);
The IotHubUri string originally had no "SharedAccessKeyName" in it, I filled it in after getting an exception telling me that there is missing information.
With this KeyName provided, I get another Exception
Hostname could not be parsed
Since I am using the same pattern as I have found in all books and other information I found on the Internet, I am simply stunned and have no idea how to go on.

Feed subscription of a Page

I want to get notifications when a new feed has landed on a designated page (by page id). After what I understand, the Realtime-update og Graph API should be able to do this trick according to https://developers.facebook.com/docs/graph-api/real-time-updates/v2.4.
So I want to add a new subscription, which I try to do with the following code:
dynamic result = client.Post(urlPath, new
{
#object = "page",
callback_url = callbackUrl,
fields = "feed",
verify_token = "654321",
access_token = accessToken
});
return result;
But when I try to run this, I'm getting the following error code:
(OAuthException - #2200) (#2200) callback verification failed: Received HTTP code 502 from proxy after CONNECT"
What do I miss?
The callback url is https://127.0.0.1:8989/ and I have a TcpListener running on the port, which does not seem to get any response/request incoming...
The application is a C# console application, so no fancy asp.net stuff or something. I'm using the Facebook .net SDK.
Should I FacebookClient.VerifyPostSubscription() or anything else that I missed out?? Maybe the SDK wraps a handle?
So the answer I'm looking for is:
- How do I create/add a subscription for feeds of a facebook page, using the .net SDK on a windows console project??
UPDATE:
I changed the loopback with a domain name, that I the NAT to my target machine, and now I actually get some encrypted data on my TcpListener!
So, the question now is, how do I respond correctly to this received respons, only by using a Tcp Client??
How you have to respond is exactly outlined in the docs you linked:
https://developers.facebook.com/docs/graph-api/real-time-updates/v2.4#setupget
It's not really clear what you mean with "TCP listener". You need to have some logic why can send HTTP responses to the Facebook servers, otherwise your service will be disregarded after some time, meaning no updates will be send.
Typically, this is implemented as a script/application in a web/application server.
Please note: The "C# SDK" is a third-party SDK and not officially supported by FB.

Azure NotificationHubClient Breaking PNS Handle

We are trying to use the NotificationHubClient in Microsoft.ServiceBus.Notifications. We are having a strange problem which the code below shows where we register the Device like so:
NotificationHubClient client = GetHubclient();
var task = client.CreateMpnsNativeRegistrationAsync(deviceToken, tags);
Task.WaitAll(task);
This registers the device fine and if we send a test toast message from the azure portal debug page it comes through to the windows phone without issue. However if we call the following:
var sentTask = client.SendMpnsNativeNotificationAsync(GetPayload());
Task.WaitAll(sentTask);
private static string GetPayload()
{
return "<wp:Notification xmlns:wp=\"WPNotification\"><wp:Toast><wp:Text1>Great News</wp:Text1><wp:Text2>Great News</wp:Text2></wp:Toast></wp:Notification>";
}
No toast notification arrives on the phone and if we then go and try to send a test toast notification again from the debug page of the azure portal it no longer works and the following error is displayed:
The Push Notification System handle for the registration is invalid
None of this is making sense, we have enabled testSend and there are no errors coming back from the client in the code, in fact it says everything was successful the first time even though this appears to break the PNS handle.
Has anyone come across this before?
It turns out that if the Xml declarations are missing:
<?xml version="1.0" encoding="utf-8"?>
Then you can no longer send push notifications to any phones you tried to send a push notification to as it is invalidated. This seems pretty awful, sure don't send the notification if the payload is invalid but why invalidate the PNS.

responding policy-file-request of flash from c#

i have developed a server application with c# and a client application with flash action script 3.0. Flash socket asking for a policy file when called from a browser with a message
<policy-file-request/>
everything is normal so far. My server is waiting for this message and sending to client a policy file string which is like this:
public const String POLICY_FILE = "<?xml version=\"1.0\"?>\n" +
"<!DOCTYPE cross-domain-policy SYSTEM \"http://www.adobe.com/xml/dtds/cross-domain-policy.dtd\">\n" +
"<cross-domain-policy>" +
"<allow-access-from domain=\"*\" to-ports=\"*\" />" +
"</cross-domain-policy>\u0000";
this string is being sent this way:
if (message.Contains("policy-file-request"))
{
client.Send(Encoding.ASCII.GetBytes(Statics.POLICY_FILE));
return;
}
I'm pretty sure that this was working but i really don't know what happened and started not working. When flash client receives this message from server, connection was succesfull and everything was going how it had to go. But now the flash client waits 20 seconds (timeout of flash socket) and throws security exception
[SecurityErrorEvent type="securityError" bubbles=false cancelable=false eventPhase=2 text="Error #2048"]
I'm stuck and can't move forward. I'm listening to port 963, server machine fully qualified name is "mypc.domain.local" which can be accessible across my network. there is also an IIS running on this machine and the flash application is hosted here.
http://mypc.domain.local:90/page.html
this is the way, i call my flash application and
mypc.domain.local:963
is the address of server running. i am also working on this machine. i tried calling the page http://localhost:90/page.html or http://127.0.0.1:90/page.html and also tried the connection to server as localhost:963 or 127.0.0.1:963. same result on every combination.
What is wrong here? what could have been changed causing my working code broke down?
Thanks.
It's hard to tell without more code, but based on what you've shown, it appears that when that request comes in, you respond with the contents of the policy file, which isn't an actual valid HTTP response. My guess for the 20 second timeout would be that it's still waiting for the HTTP headers.
If possible, try to use the HTTP classes already in the BCL instead of doing http 'manually', but if you have to do the socket stuff yourself, then use something like Fiddler during debugging since it's great for identifying violations of the HTTP protocol.

Categories

Resources