Click here to Skip to main content
15,881,781 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Actually 500 bad request is shown in the time of Http request method is run

using namespace std;
	const wstring domain = L"localhost";
	const wstring requestHeader = L"Content-Type: application/json";
	int port = 7276;
	bool https = true;

	using namespace WinHttpWrapper;

	HttpRequest req(domain, port, https);
	HttpResponse response;
	cout << "Action: Create Product with Id = 1" << endl;
	req.Post(L"/api/SuperHero/create",
		requestHeader,
		R"({"id": 4,
  "name": "Deepak",
  "firstName": "Kumar",
  "lastName": "singh",
  "place": "Agra"})",
		response);
	cout << "Returned Status:" << response.statusCode << endl << endl;
	response.Reset();


What I have tried:

<using namespace std;
	const wstring domain = L"localhost";
	const wstring requestHeader = L"Content-Type: application/json";
	int port = 7276;
	bool https = true;

	using namespace WinHttpWrapper;

	HttpRequest req(domain, port, https);
	HttpResponse response;
	cout << "Action: Create Product with Id = 1" << endl;
	req.Post(L"/api/SuperHero/create",
		requestHeader,
		R"({""id": 4,
  "name": "Deepak",
  "firstName": "Kumar",
  "lastName": "singh",
  "place": "Agra"})",
		response);
	cout << "Returned Status:" << response.statusCode << endl << endl;
	response.Reset();
Posted
Updated 24-Jan-23 23:33pm
v3
Comments
Richard Deeming 24-Jan-23 5:54am    
A "400 bad request" error means the server doesn't recognise the data you've sent it, or the data you've sent is invalid.

You'll need to consult the documentation for the service you're trying to call, or talk to the person who wrote it, to find out what the problem is. We can't do that for you.
Richard Deeming 24-Jan-23 6:28am    
Your edited question makes even less sense.

A "bad request" error would have status code 400.
A 500 error would be an "internal server error".
There is no such thing as a "500 bad request" error.

And regardless of whether you're getting a 400 or 500 error, you still need to talk to the person who wrote the service you're trying to call to find out what the problem is. Nobody here can do that for you!
Andre Oosthuizen 25-Jan-23 5:40am    
The HTTP status code 500 is a generic error response. It means that the server encountered an unexpected condition that prevented it from fulfilling the request sent to it. This error is usually returned by the server when no other error code is suitable, I thus suggest that you do some error catching code which will, in return, point you to the exact problem in your code.

With a specific error and line of code where error occurred, we will be able to assist more.
Sandeep Mewara 26-Jan-23 0:11am    
For more on 500 Internal server error, read: HTTP 500 – Internal server error[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900