0

I am currently working on a simple app to make my life easier. I made an android app which lets me pick a file and uploads it to a server. I am working on a windows PC c# app that sends its ip (dynamic) and its open port to my server. Whenever the server receives a file from my phone, I want it to send a POST request to my PC.

I am fairly new to web stuff (I have done tons of coding before though), but as far as I understand only a server can receive a POST request. How can I make a C# server that runs on my PC with a dynamic IP and receives POST requests?

I have been struggling with this for a while now, just simple keywords I should research would be very helpful, thanks.

user3000140
  • 319
  • 2
  • 11

2 Answers2

0

HTTP is a protocol which lets Web Servers and Clients communicate. It requires you to have a web server (IIS, Apache or other) to respond to client http requests.

Client can send a GET, POST and others request type messages.

The prefable way is to send a web client using a WebClient class. Here is a sample taken from another answer given by Andrew

string URI = "site.com/mail.php";
using (WebClient client = new WebClient())
{
    System.Collections.Specialized.NameValueCollection postData = 
        new System.Collections.Specialized.NameValueCollection()
       {
              { "to", emailTo },  
              { "subject", currentSubject },
              { "body", currentBody }
       };
    string pagesource = Encoding.UTF8.GetString(client.UploadValues(URI, postData));
}
Community
  • 1
  • 1
Orel Eraki
  • 11,940
  • 3
  • 28
  • 36
0

I would create some kind of server application using WebAPI, SignalIR, WCF or ASMX web services. All of these can handle server/client communication and would make it easy to communicate with your device.

Justin
  • 4,002
  • 2
  • 19
  • 21