how to request url that need Authorization?

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

how to request url that need Authorization?

Postby tiplip » Wed Apr 13, 2016 2:21 am

Hi,

In generally, I can use the following codes to get something on one URL

Code: Select all
  // Create a CefRequest for the specified URL.
  CefRefPtr<CefRequest> request = CefRequest::Create();
  request->SetURL(url);
  request->SetMethod("GET");
 
  // Callback to be executed on request completion.
  // It's safe to use base::Unretained() here because there is only one
  // RequestClient pending at any given time and we explicitly detach the
  // callback in the Handler destructor.
  const RequestClient::Callback& callback =
      base::Bind(&HappSyncHandler::OnRequestComplete, base::Unretained(this));
 
  // Create and start the new CefURLRequest.
  urlrequest_ = CefURLRequest::Create(request,
                                      new RequestClient(callback),
                                      NULL);


if the URL I want to visit need Authorization, I can do it on Windows:
Code: Select all
   lpszAgent = "WinInetGet/0.1";
    hInternet = InternetOpen(lpszAgent,INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
   lpszVerb = "GET";
   serverDomain="api.website.com";
   port=443;

InternetConnect(hInternet, serverDomain, port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);

    DWORD dwOpenRequestFlags = INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP |
                               INTERNET_FLAG_KEEP_CONNECTION |
                               INTERNET_FLAG_NO_AUTH |
                               INTERNET_FLAG_NO_COOKIES |
                               INTERNET_FLAG_NO_UI |
                               //use HTTPS
                               INTERNET_FLAG_SECURE |
                               INTERNET_FLAG_RELOAD;

    //init Request
   string Authheader= "Authorization: Bearer "+token;
    HINTERNET hRequest = HttpOpenRequest(hConnect, lpszVerb, lpszObjectName, NULL,
                                         NULL, NULL,
                                         dwOpenRequestFlags, 0);
   HttpAddRequestHeaders(hRequest, Authheader.c_str(),    -1, HTTP_ADDREQ_FLAG_ADD|HTTP_ADDREQ_FLAG_REPLACE);
    //send Request
    BOOL bResult = HttpSendRequest(hRequest, NULL, 0, NULL, 0);


but how can I do the same thing with CEF3 api?
tiplip
Mentor
 
Posts: 77
Joined: Thu Mar 26, 2015 3:09 am

Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 175 guests