roadlabs / chromiumembedded

Automatically exported from code.google.com/p/chromiumembedded
0 stars 1 forks source link

How to custom http request header? #1531

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I want to add "Accept-Language" header to the request, where the browser sent a 
request to the server.
so i try to do this in "cefclient" project.

1. add "OnBeforeResourceLoad" to "ClientHandler" class in "client_handler.h" 
file.
  virtual bool OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
      CefRefPtr<CefFrame> frame,
      CefRefPtr<CefRequest> request) OVERRIDE;

2. add code to the method in "client_handler.cpp" file.
bool ClientHandler::OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
    CefRefPtr<CefFrame> frame,
    CefRefPtr<CefRequest> request) {
    CefRequest::HeaderMap headerMap;
    request->GetHeaderMap(headerMap);

    // debug, show url.
    CefString URL = request->GetURL();
    std::wstring url = URL.c_str();

    headerMap.erase("Accept-Language");
    headerMap.insert(std::make_pair("Accept-Language", "zh-CN,zh;q=0.8,en;q=0.6,zh-TW;q=0.4"));
    request->SetHeaderMap(headerMap);

    return false;
}

After all, i run cefclient and open devtools, in "Network" pane, i only see 2 
http headers:
1.Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=
0.8
2.User-Agent:Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, 
like Gecko) Chrome/39.0.2171.95 Safari/537.36
no "Accept-Language" header.

so, what should i do to add "Accept-Language" header to the http request?

--
cef:cef_binary_3.2171.1979_windows32, cef_binary_3.1750.1738_windows32
OS: windows8 x64

Original issue reported on code.google.com by mark.li....@gmail.com on 12 Feb 2015 at 12:54

GoogleCodeExporter commented 9 years ago
See issue #318 for how to set Accept-Language header.

Original comment by magreenb...@gmail.com on 24 Feb 2015 at 10:36

GoogleCodeExporter commented 9 years ago
Thanks for your response. I will follow issue #318 and revision 2034.

Original comment by mark.li....@gmail.com on 26 Feb 2015 at 2:24