How to use POST and PUT method using arduino with Ethernet Shield?

I'm using ASP.NET web server, it works well with Postman but doesn't work with my arduino. Please help me. Sorry my english is not good.

ASP.NET

[HttpGet]
        public Student GetStudent(string ID)
        {
            StudentServerDbContext db = new StudentServerDbContext();
            var query = (from a in db.iSTUDENTs
                         where a.STUDENTID == ID
                         select a);

            var data = query.Select(x => new Student
            {
                _08STATUS = x.iPERMISSION.STUDENTSTATUS,
            }).First();
            return data;
        }

        public class Student
        {
            public string _08STATUS { get; set; }
        }
        
[HttpPost]
        public bool UpdateOut(string ID)
        {
. . .              
                        b.INOUTID = 0;
                        b.STUDENTID = ID;
                        b.OUTTIME = DateTime.Now;
                        b.INTIME = DateTime.Now;

                        db.iINOUTs.Add(b);
                    }
                    db.SaveChanges();
                    return true;
                }
                return false;
        }

        [HttpPut]
        public bool UpdateIn(string ID)
        {
. . .
                        b.INTIME = DateTime.Now;
                    }
                    db.SaveChanges();
                    return true;
                }
                return false;
        }

.INO

      	client.println("GET /api/student/" + id + " HTTP/1.1");
     	 client.println("Host: 192.168.1.1");
     	 client.println();
…
client.find(":\"");
               client.readBytesUntil('\"', _status, sizeof(_status));
               myGLCD.print("Status: ", 170, 150);
               myGLCD.print(_status, 265, 150);
…
if(strcmp(_status,"IN") == 0){
                              client.println("POST /api/student/" + id + " HTTP/1.1");
     		 client.println("Host: 192.168.1.1");
      		client.println("Connection: close");
     		 client.println("Content-Type: application/x-www-form-urlencoded");
     		 client.println("Content-Length: 0");
      		client.println();
                  }
                  else {
     		client.println("PUT /api/student/" + id + " HTTP/1.1");
      		client.println("Host: 192.168.1.1");
      		client.println("Connection: close");
      		client.println("Content-Type: application/x-www-form-urlencoded");
      		client.println("Content-Length: 0");
      		client.println();                  
}

it works well with Postman but doesn't work with my arduino.

A bit more information about what output you get and why you think that was wrong would help.

                              client.println("POST /api/student/" + id + " HTTP/1.1");
     		client.println("Host: 192.168.1.1");
      		client.println("Connection: close");
     		client.println("Content-Type: application/x-www-form-urlencoded");
     		client.println("Content-Length: 0");
      		client.println();

In most cases a POST with no data doesn't make sense. I have no clue about that Microsoft stuff you use on the server so decide yourself. Same applies for PUT.

Do the requests reach the server? What tells the server log?

Post complete code and not excerpts. In my experience very often the error is in the part of the code that wasn't posted.

I tried to fix it but it still didn't work. Help me please.
It still works well with both Postman and Fiddler.
GET method works well.

ASP.NET

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using MODEL.EF;
using STUDENTSERVER.Models;

namespace STUDENTSERVER.Controllers.StudentController
{
    public class StudentController : ApiController
    {
        private static readonly string[] VietnameseSigns = new string[]
        {
            "aAeEoOuUiIdDyY",
            "áàạảãâấầậẩẫăắằặẳẵ",
            "ÁÀẠẢÃÂẤẦẬẨẪĂẮẰẶẲẴ",
            "éèẹẻẽêếềệểễ",
            "ÉÈẸẺẼÊẾỀỆỂỄ",
            "óòọỏõôốồộổỗơớờợởỡ",
            "ÓÒỌỎÕÔỐỒỘỔỖƠỚỜỢỞỠ",
            "úùụủũưứừựửữ",
            "ÚÙỤỦŨƯỨỪỰỬỮ",
            "íìịỉĩ",
            "ÍÌỊỈĨ",
            "đ",
            "Đ",
            "ýỳỵỷỹ",
            "ÝỲỴỶỸ"
        };

        public static string RemoveSign4VietnameseString(string str)
        {
            for (int i = 1; i < VietnameseSigns.Length; i++)
            {
                for (int j = 0; j < VietnameseSigns[i].Length; j++)
                    str = str.Replace(VietnameseSigns[i][j], VietnameseSigns[0][i - 1]);
            }
            return str;
        }

        [HttpGet]
        public IEnumerable<iSTUDENT> GetStudentLists()
        {
            StudentServerDbContext db = new StudentServerDbContext();
            var students = db.iSTUDENTs;
            return students.ToList();
        }
        [HttpGet]
        public Student GetStudent(string ID)
        {
            StudentServerDbContext db = new StudentServerDbContext();
            var query = (from a in db.iSTUDENTs
                         where a.STUDENTID == ID
                         select a);

            var data = query.Select(x => new Student
            {
                _01APPLY = x.iPERMISSION.SENDAPPLY,
                _02NAME = x.STUDENTNAME,
                _03CLASS = x.CLASSID,
                _04SEX = x.STUDENTSEX,
                _05BIRTHDAY = x.STUDENTBIRTHDAY,
                _06ADDRESS = x.STUDENTADDRESS,
                _07PHONE = x.STUDENTPHONE,
                _08STATUS = x.iPERMISSION.STUDENTSTATUS,
                _09OUTTIME = x.iPERMISSION.STUDENTOUTTIME,
                _10INTIME = x.iPERMISSION.STUDENTINTIME
            }).First();

            data._02NAME = RemoveSign4VietnameseString(data._02NAME);
            data._04SEX = RemoveSign4VietnameseString(data._04SEX);
            data._06ADDRESS = RemoveSign4VietnameseString(data._06ADDRESS);
            return data;
        }

        public class Student
        {
            public bool _01APPLY { get; set; }
            public string _02NAME { get; set; }
            public string _03CLASS { get; set; }
            public string _04SEX { get; set;  }
            public string _05BIRTHDAY { get; set; }
            public string _06ADDRESS { get; set; }
            public string _07PHONE { get; set; }
            public string _08STATUS { get; set; }
            public string _09OUTTIME { get; set; }
            public string _10INTIME { get; set; }
        }

        [HttpPost]
        public bool PostOut(StudentID studentid)
        {
            string id = studentid.ID;
            if (!String.IsNullOrEmpty(id))
            {
                try
                {
                    StudentServerDbContext db = new StudentServerDbContext();
                    iSTUDENT a = db.iSTUDENTs.FirstOrDefault(x => x.STUDENTID == id);
                    iINOUT b = new iINOUT();
                    var c = db.iINOUTs.OrderByDescending(x => x.INOUTID);
                    if (a.iPERMISSION.SENDAPPLY)
                    {
                        if (a.iPERMISSION.STUDENTSTATUS == "IN")
                        {
                            a.iPERMISSION.STUDENTSTATUS = "OUT";
                            a.iPERMISSION.STUDENTLOG = "OUT " + DateTime.Now.ToString();
                            a.iPERMISSION.STUDENTALLLOG = "OUT " + DateTime.Now.ToString() + "\n" + a.iPERMISSION.STUDENTALLLOG;

                            if (c.FirstOrDefault(x => x.STUDENTID == id) != null)
                            {
                                if (c.FirstOrDefault(x => x.STUDENTID == id).OUTTIME.Month == DateTime.Now.Month)
                                {
                                    a.iPERMISSION.STUDENTMONTHLOG = "OUT " + DateTime.Now.ToString() + "\n" + a.iPERMISSION.STUDENTMONTHLOG;
                                    a.iPERMISSION.STUDENTCOUNT++;
                                }
                                else
                                {
                                    a.iPERMISSION.STUDENTMONTHLOG = "OUT " + DateTime.Now.ToString();
                                    a.iPERMISSION.STUDENTCOUNT = 1;
                                }
                            }
                            else
                            {
                                a.iPERMISSION.STUDENTMONTHLOG = "OUT " + DateTime.Now.ToString() + "\n" + a.iPERMISSION.STUDENTMONTHLOG;
                                a.iPERMISSION.STUDENTCOUNT++;
                            }

                            b.INOUTID = 0;
                            b.STUDENTID = id;
                            b.OUTTIME = DateTime.Now;
                            b.INTIME = DateTime.Now;

                            db.iINOUTs.Add(b);
                        }
                        db.SaveChanges();
                        return true;
                    }
                    return false;
                }
                catch
                {
                    return false;
                }
            }
            return false;
        }

        [HttpPut]
        public bool PutIn(StudentID studentid)
        {
            string id = studentid.ID;
            if (!String.IsNullOrEmpty(id))
            {
                try
                {
                    StudentServerDbContext db = new StudentServerDbContext();
                    iSTUDENT a = db.iSTUDENTs.FirstOrDefault(x => x.STUDENTID == id);
                    var c = db.iINOUTs.OrderByDescending(x => x.INOUTID);
                    iINOUT b = c.FirstOrDefault(x => x.STUDENTID == id);
                    if (a.iPERMISSION.SENDAPPLY)
                    {
                        if (a.iPERMISSION.STUDENTSTATUS == "OUT")
                        {
                            a.iPERMISSION.STUDENTSTATUS = "IN";
                            a.iPERMISSION.STUDENTLOG = "IN " + DateTime.Now.ToString();
                            a.iPERMISSION.STUDENTMONTHLOG = "IN " + DateTime.Now.ToString() + "\n" + a.iPERMISSION.STUDENTMONTHLOG;
                            a.iPERMISSION.STUDENTALLLOG = "IN " + DateTime.Now.ToString() + "\n" + a.iPERMISSION.STUDENTALLLOG;

                            b.INTIME = DateTime.Now;
                        }
                        db.SaveChanges();
                        return true;
                    }
                    return false;
                }
                catch
                {
                    return false;
                }
            }
            return false;
        }
    }
}

.INO

void getphoto(String id){
      client.setTimeout(1000);
      client.println("GET /home/getphoto/" + id + " HTTP/1.1");
      client.println("Host: 192.168.1.1");
      client.println();
}
void sendrequest(String id){
      client.setTimeout(1000);
      client.println("GET /api/student/" + id + " HTTP/1.1");
      client.println("Host: 192.168.1.1");
      client.println();
}
void updateout(String id){
      char outBuf[40];
      client.println("POST /api/student HTTP/1.1");
      client.println("Host: 192.168.1.1");
      client.println("Content-Type: application/json");
      sprintf(outBuf,"Content-Length: %u",9 + id.length());
      client.println(outBuf);
      client.println();
      client.println("{\"id\":\"4499164121146\"}");
}
void updatein(String id){
      char outBuf[40];      
      client.println("PUT /api/student HTTP/1.1");
      client.println("Host: 192.168.1.1");
      client.println("Content-Type: application/json");
      sprintf(outBuf,"Content-Length: %u",9 + id.length());
      client.println(outBuf);
      client.println();
      client.println("{\"id\":\"4499164121146\"}");
}

void  printRfid(){
     if (cardNum != '\0') {   
                  resetscreen();

                  char endOfHeaders[] = "\r\n\r\n";
                  bool photo = false;
                                    
                  sendrequest(cardNum);

                  myGLCD.setColor(255, 255, 255);

                  // Skip HTTP headers
                  char header[256];
                  client.readBytesUntil(endOfHeaders, header, sizeof(header));
                  Serial.println(header);
                  Serial.println();
                  client.find(endOfHeaders);
                        
                  char _apply[6] = {0};
                  char _name[26] = {0}, _class[11] = {0}, _sex[4] = {0}, _birthday[11] = {0}, _address[21] = {0}, _phone[12] = {0}, _status[4] = {0}, _outtime[11] = {0}, _intime[11] = {0};
                  
                  client.find(":");                 
                  client.readBytesUntil(',', _apply, sizeof(_apply));
                  if(strcmp(_apply,"true") == 0){                             
                              client.find(":\"");
                              client.readBytesUntil('\"', _name, sizeof(_name));
                              myGLCD.print(_name, 170, 25);
                              
                              client.find(":\"");
                              client.readBytesUntil('\"', _class, sizeof(_class));
                              myGLCD.print(_class, 170, 50);
                              
                              client.find(":\"");
                              client.readBytesUntil('\"', _sex, sizeof(_sex));
                              myGLCD.print(_sex, 170, 75);

                              client.find(":\"");
                              client.readBytesUntil('\"', _birthday, sizeof(_birthday));
                              myGLCD.print(_birthday, 220, 75);

                              client.find(":\"");
                              client.readBytesUntil('\"', _address, sizeof(_address));
                              myGLCD.print(_address, 170, 100);

                              client.find(":\"");
                              client.readBytesUntil('\"', _phone, sizeof(_phone));
                              myGLCD.print(_phone, 170, 125);

                              client.find(":\"");
                              client.readBytesUntil('\"', _status, sizeof(_status));
                              myGLCD.print("Trang thai: ", 170, 150);
                              myGLCD.print(_status, 265, 150);

                              client.find(":\"");
                              client.readBytesUntil('\"', _outtime, sizeof(_outtime));
                              myGLCD.print("Tu: ", 170, 175);
                              myGLCD.print(_outtime, 220, 175);

                              client.find(":\"");
                              client.readBytesUntil('\"', _intime, sizeof(_intime));
                              myGLCD.print("Den: ", 170, 200);
                              myGLCD.print(_intime, 220, 200);

                                                // fix problem while waiting
                              while(client.available()){
                                    byte buffer;
                                    client.read(buffer, 1);
                              }
                  
                              photo = true;
                              //digitalWrite(15, LOW);
                              digitalWrite(16, HIGH);
                              delay(100);
                              digitalWrite(15, HIGH);
                              digitalWrite(16, LOW);
                   }
                   else{
                        while(client.available()){
                              byte buffer;
                              client.read(buffer, 1);
                              }

                              myGLCD.print("Khong duoc giai quyet ra/vao cong.", CENTER, 105);
                              
                              digitalWrite(14, HIGH);
                              delay(100);
                              digitalWrite(14, LOW);
                   }                                        
                  
                  if(photo){
                        getphoto(cardNum);
                        myGLCD.setColor(255, 255, 255);
                        
                        // Skip HTTP headers
                        client.find(endOfHeaders);

                        char buf[300];
                        unsigned int row = 0;
                        char bufx[100];
                        client.read(bufx, 66);
                        
                        while(client.available()){
                              client.read(buf, 300);
                              myGLCD.drawRaw(10, 220-row, 150, 1, buf);
                              row++;
                        }
                        
                        // fix problem while waiting
                        while(client.available()){
                              byte buffer;
                              client.read(buffer, 1);
                        }
                  }
                  
                  if(strcmp(_status,"OUT") == 0){
                        updatein(cardNum);
                  }
                  else {
                        updateout(cardNum);
                  }
                  
                  cardNum.remove(0);                  
      }
}

Posman code

POST /api/student HTTP/1.1
Host: localhost:55739
Content-Type: application/json
Cache-Control: no-cache
Postman-Token: 3d4e0dd4-ff55-6b29-c304-951b720082a5

{"id":"4499164121146"}

Fiddler code

PUT http://localhost:55739/api/student HTTP/1.1
Host: localhost:55739
Content-Type: application/json
Content-Length: 22

{"id":"4499164121146"}

My code worked. The only thing I lack is "delay (1000);". I'm going crazy. Perhaps the POST and PUT functions need a delay to process. Thank you.

The only thing I lack is "delay (1000);". I'm going crazy. Perhaps the POST and PUT functions need a delay to process.

That might have fixed it for the moment but sooner or later it will reappear. You probably didn't handle the server response or something similar. As you didn't post complete code (that would compile) you're on your own to fix it correctly.