1

Some advice needed - I have an app running on windows 10 PC which sends out data in text_binary or json format which will be one line of text normally (small file of roughly 8kb).

It will look something like this -

{source={ivarId={f1d22827-1650-41a0-a31e-28621430bc7d}, channel=1}, common={type=AUDIT_LOG, time=2020-04-20T15:40:11.256Z}, auditLog={clientId=2148, clientIp=127.0.0.1, account=, command=START_LIVE, parameters=[{name=channelId, value=1}, {name=answer, value=1}, {name=replyType, value=1}], result=STATUS_OK}, id={be138cc4-321c-41a9-8d2f-25a1e5d058fc}, addInfo={ivarIp=192.168.1.17}, images=[]}

The protocol it uses to send out is HTTP so i have to set up a webservice to receive this data and provide the URL of the webservice to the application so it can send.

I simply need the webservice to receive this text file and store it somewhere locally. The webservice has to be installed on the same Windows 10 PC where the app resides.

Any ideas on where to get started on this, that is what would be the best method for accepting this file and storing it?

hicksgt
  • 13
  • 2
  • Have you researched on API services like ASP.NET Core WebAPI? Also, have you read online about serverless File Databases like LiteDB or SQLLite? If you do your findings and supply more information, the community will help you better. – Olorunfemi Davis Jun 05 '20 at 10:05

1 Answers1

0

On top of my head, I can think of a simple python script to start an HTTP server and write the request body to a file.

#!/usr/bin/python3

from http.server import HTTPServer, BaseHTTPRequestHandler

class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):

    def do_POST(self):
        content_length = int(self.headers['Content-Length'])
        body = self.rfile.read(content_length)
        self.send_response(200)
        self.end_headers()
        f = open("request.txt", "wb") # you can use any name or probably derive name from request
        f.write(body)
        f.close()

httpd = HTTPServer(('localhost', 8001), SimpleHTTPRequestHandler)
httpd.serve_forever()

This is a very basic example but it'll give you a point to start from. It can be modified to specify the file location/name.

This answer is under the assumption that the file content is being sent in the request body.

You can refer to this answer if your request has file as multipart data

Arpit Tyagi
  • 173
  • 1
  • 10
  • Thanks for the reply. Seems very simple.There is no multipart data. Does this script work in isolation or is it used to configure a webserver? – hicksgt Jun 05 '20 at 08:54
  • This script will work in isolation as long as you have python on your machine. If it's a windows box, you might need to modify the shebang line – Arpit Tyagi Jun 05 '20 at 15:13
  • Arpit this has worked for me, thanks so much. I would upvote you but i cant yet. Is there a way to get this script to run on windows start? – hicksgt Jun 07 '20 at 13:39
  • Can you trying adding a shortcut to your python script in 'C:\Documents and Settings\All Users\Start Menu\Programs\Startup' directory – Arpit Tyagi Jun 08 '20 at 22:19