ABCD
ABCD

Reputation: 399

HttpRequestException: An error occurred while sending the request

I developed a project using asp.net core MVC and cosmos db. When I try to post the form I got

HttpRequestException: An error occurred while sending the request error.

I debug it using break point.

 await 'client.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri("HRDB", "EmployeesCollection"), employee);'

Above link so me the error. please help me to fix it .

code:

' [HttpPost]
        public async Task<ActionResult> AddEmployee(Employee employee)


       {

            await client.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri("HRDB", "EmployeesCollection"), employee);

            return RedirectToAction("Employees");
        }'

Error :

enter image description here

enter image description here

Upvotes: 0

Views: 3829

Answers (1)

Mohit Verma
Mohit Verma

Reputation: 5294

I downloaded your code and tried to add an employee ,am getting the same error you are getting.

Below point to check :

  • Make sure your URL is correct and Cosmos DB is not blocked as per your org policy.

Here is very simple and very nice article to get started with Azure cosmos DB in web application.

https://learn.microsoft.com/en-us/azure/cosmos-db/sql-api-dotnet-application

And finally start adding your model and add it.

Hope it helps.

Upvotes: 1

Related Questions