Click here to Skip to main content
15,907,001 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
After post username and password one token generate that token I want to authrize in another method to break bearer

What I have tried:

#include <iostream>
#include "WinHttpWrapper.h"
#include <string.h>

void PrintDictionary(const std::unordered_map<std::wstring, std::wstring="">& dict);

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

	HttpRequest req(domain, port, https);
	HttpResponse response;
	cout << "Returned Status:" << response.statusCode << endl;
	cout << "Content Length:" << response.contentLength << endl;
   string token = "bearer " + response.text;
   wcout << endl << response.header << endl;
   cout << "Get the register data by id" << endl;
	req.Get(L"/api/Auth/GetId",L"", response);
	cout << "Returned Status:" << response.statusCode;
	cout << "Returned Text:"<< response.text << endl;
Updated 30-Jan-23 2:39am
Shao Voon Wong 31-Jan-23 2:45am    
Why are you setting https to true? Is the website hosted on https URL? Check the URL on your web browser. Anyway, it is an error on the web server, please debug your web server and see why it returns 401.
Bal krishna sharma 1-Feb-23 2:56am    
If the Url is wrong then firstly Post class token generate it shown 200 ok nad the Get data where I have to provide the authorization

1 solution

Confirm the URL Is Correct. This might sound obvious, but the 401 error code might appear if the user entered the wrong URL in the browser's address bar. ...
Clear User End Issues. ...
Check Authentication Credentials. ...
Disable Password Protection. ...
Troubleshoot the Code.
Share this answer
Richard Deeming 31-Jan-23 8:17am    
If the URL was wrong, you'd get a 404 error, not a 401 error.

And "disable password protection" is probably the worst advice you could give.

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