title: Can't sent web request from .Net web api to remote server
body: <p>I am trying to send a post request to my remote server from my .net web api project as mentioned below,</p>
  
  <pre><code>        [AcceptVerbs("GET", "POST")]
          public string POST()
          {
  
             var values = new NameValueCollection();
             values["login_id"] = "XXXX";
             values["password"] = "XXXXXXXX";
  
             var response = client.UploadValues("http://10.17.73.60/api/login", values);
  
             var responseString = Encoding.Default.GetString(response);
  
             Console.WriteLine("Rasindu :- " + responseString);
  
             return responseString;
          }
  </code></pre>
  
  <p>It gives me follwing error,</p>
  
  <blockquote>
    <p> An error has occurred. 
    The remote server returned an error: (400) Bad Request.
    
    System.Net.WebException  at
    System.Net.WebClient.UploadValues(Uri address, String method,
    NameValueCollection data) at System.Net.WebClient.UploadValues(String
    address, NameValueCollection data) at
    EmployeeWebApiService.Controllers.AppController.POST() in
    C:\Users\rdealk\Documents\Visual Studio
    2017\Projects\EmployeeWebApiService\EmployeeWebApiService\Controllers\AppController.cs:line
    37 at lambda_method(Closure , Object , Object[] ) at
    System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.&lt;>c__DisplayClass6_1.b__3(Object
    instance, Object[] methodParameters) at
    System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object
    instance, Object[] arguments) at
    System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext
    controllerContext, IDictionary`2 arguments, CancellationToken
    cancellationToken) --- End of stack trace from previous location where
    exception was thrown --- at
    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
    task) at
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
    task) at
    System.Web.Http.Controllers.ApiControllerActionInvoker.d__1.MoveNext()
    --- End of stack trace from previous location where exception was thrown --- at
    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
    task) at
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
    task) at
    System.Web.Http.Controllers.ActionFilterResult.d__5.MoveNext()
    --- End of stack trace from previous location where exception was thrown --- at
    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
    task) at
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
    task) at
    System.Web.Http.Dispatcher.HttpControllerDispatcher.d__15.MoveNext()
     </p>
  </blockquote>
  
  <p>I could be able to send the above mentioned request using Postman successfully and also I sent the above request to a different server(Not remote server) that was also possible. Therefore I think there is a problem in .net configuration but I have no idea about it. </p>
  
  <p>Below is my response to my request in postman(successfully sent)</p>
  
  <pre><code>{
      "User": {
          "user_id": "1",
          "name": "Administrator",
          "gender": "1",
          "birthday": "1977-10-08T04:00:00.00Z",
          "photo_exists": "false",
          "pin_exists": "false",
          "login_id": "admin",
          "password_exists": "true",
          "updated_count": "0",
          "last_modified": "0",
          "start_datetime": "2001-01-01T00:00:00.00Z",
          "expiry_datetime": "2030-12-31T23:59:00.00Z",
          "security_level": "0",
          "display_duration": "20",
          "display_count": "3",
          "permission": {
              "id": "1",
              "name": "Administrator",
              "description": "this is a permission for Administrator",
              "filter": {
                  "UserGroup": [
                      "1"
                  ],
                  "DeviceGroup": [
                      "1"
                  ],
                  "DoorGroup": [
                      "1"
                  ],
                  "ElevatorGroup": [
                      "1"
                  ],
                  "ZoneType": [
                      "-1"
                  ],
                  "AccessGroup": [
                      "0"
                  ],
                  "GraphicMapGroup": [
                      "1"
                  ]
              },
              "module": {
                  "Dashboard": {
                      "read": "true",
                      "write": "true"
                  },
                  "User": {
                      "read": "true",
                      "write": "true"
                  },
                  "Device": {
                      "read": "true",
                      "write": "true"
                  },
                  "Door": {
                      "read": "true",
                      "write": "true"
                  },
                  "Elevator": {
                      "read": "true",
                      "write": "true"
                  },
                  "Zone": {
                      "read": "true",
                      "write": "true"
                  },
                  "AccessControl": {
                      "read": "true",
                      "write": "true"
                  },
                  "Monitoring": {
                      "read": "true",
                      "write": "true"
                  },
                  "TA": {
                      "read": "true",
                      "write": "true"
                  },
                  "Setting": {
                      "read": "true",
                      "write": "true"
                  },
                  "Video": {
                      "read": "true",
                      "write": "true"
                  },
                  "Visitor": {
                      "read": "true",
                      "write": "true"
                  }
              },
              "device": {
                  "id": "547239744"
              },
              "user": {
                  "id": "1",
                  "id": "1319",
                  "id": "1970",
                  "id": "2345",
                  "id": "2373"
              }
          },
          "inherited": "false",
          "user_group_id": {
              "id": "1",
              "name": "All Users"
          },
          "disabled": "false",
          "expired": "false",
          "fingerprint_template_count": "0",
          "face_count": "0",
          "card_count": "0",
          "need_to_update_pw": "false"
      },
      "Response": {
          "code": "0",
          "link": "http://biostar.com/response.html",
          "message": "Success"
      }
  }
  </code></pre>
  
  <p>Headers according to the postman request that I sent,</p>
  
  <pre><code>bs-session-id  -  97e09c82546d4d9a8b7c4422dc0a49d2
  Content-Type   -  application/json;charset=UTF-8
  Content-Length -  1510
  </code></pre>
  
  <p>What is the best solution for this problem ?</p>