Posts

Showing posts with the label Http

Accessing The Web Page's HTTP Headers In JavaScript

Answer : It's not possible to read the current headers. You could make another request to the same URL and read its headers, but there is no guarantee that the headers are exactly equal to the current. Use the following JavaScript code to get all the HTTP headers by performing a get request: var req = new XMLHttpRequest(); req.open('GET', document.location, false); req.send(null); var headers = req.getAllResponseHeaders().toLowerCase(); alert(headers); Unfortunately, there isn't an API to give you the HTTP response headers for your initial page request. That was the original question posted here. It has been repeatedly asked, too, because some people would like to get the actual response headers of the original page request without issuing another one. For AJAX Requests: If an HTTP request is made over AJAX, it is possible to get the response headers with the getAllResponseHeaders() method. It's part of the XMLHttpRequest API. To see how this can be ap...

Can PHP CURL Retrieve Response Headers AND Body In A Single Request?

Answer : One solution to this was posted in the PHP documentation comments: http://www.php.net/manual/en/function.curl-exec.php#80442 Code example: $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 1); // ... $response = curl_exec($ch); // Then, after your curl_exec call: $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); $header = substr($response, 0, $header_size); $body = substr($response, $header_size); Warning: As noted in the comments below, this may not be reliable when used with proxy servers or when handling certain types of redirects. @Geoffrey's answer may handle these more reliably. Many of the other solutions offered this thread are not doing this correctly. Splitting on \r\n\r\n is not reliable when CURLOPT_FOLLOWLOCATION is on or when the server responds with a 100 code. Not all servers are standards compliant and transmit just a \n for new lines. Detecting the size of the headers via CURLINFO_HEA...

Best Lightweight Web Server (only Static Content) For Windows

Answer : You can use Python as a quick way to host static content. On Windows, there are many options for running Python, I've personally used CygWin and ActivePython. To use Python as a simple HTTP server just change your working directory to the folder with your static content and type python -m SimpleHTTPServer 8000 , everything in the directory will be available at http:/localhost:8000/ Python 3 To do this with Python, 3.4.1 (and probably other versions of Python 3), use the http.server module: python -m http.server <PORT> # or possibly: python3 -m http.server <PORT> # example: python -m http.server 8080 On Windows: py -m http.server <PORT> Have a look at mongoose: single executable very small memory footprint allows multiple worker threads easy to install as service configurable with a configuration file if required The smallest one I know is lighttpd. Security, speed, compliance, and flexibility -- all of these describe ligh...

Axios Delete Request With Body And Headers?

Answer : So after a number of tries, I found it working. Please follow the order sequence it's very important else it won't work axios.delete(URL, { headers: { Authorization: authorizationToken }, data: { source: source } }); axios.delete does support a request body. It accepts two parameters: url and optional config. You can use config.data to set the request body and headers as follows: axios.delete(url, { data: { foo: "bar" }, headers: { "Authorization": "***" } }); See here - https://github.com/axios/axios/issues/897 Here is a brief summary of the formats required to send various http verbs with axios: GET : Two ways First method axios.get('/user?ID=12345') .then(function (response) { // Do something }) Second method axios.get('/user', { params: { ID: 12345 } }) .then(function (response) { // Do something }) The two above are equivalent. Observe the params...

Adding Http Headers To Window.location.href In Angular App

Answer : When you use $window.location.href the browser is making the HTTP request and not your JavaScript code. Therefore, you cannot add a custom header like Authorization with your token value. You could add a cookie via JavaScript and put your auth token there. The cookies will automatically be sent from the browser. However, you will want to review the security implications of using a cookie vs. a header. Since both are accessible via JavaScript, there is no additional attack vector there. Unless you remove the cookie after the new page loads, there may be a CSRF exploit available. This answer is NOT a safe way, as the token is exposed in the URL, which is logged in browser history, access logs, etc. Use a domain cookie instead. I'll leave the answer as it can be an easy way to debug in your local setup. I am using JWT as authentication on a Laravel PHP backend, and it works by putting ?token=... in the URL. For example, when using AngularJS with satellizer plug...

"CAUTION: Provisional Headers Are Shown" In Chrome Debugger

Image
Answer : The resource could be being blocked by an extension (AdBlock in my case). The message is there because the request to retrieve that resource was never made, so the headers being shown are not the real thing. As explained in the issue you referenced, the real headers are updated when the server responds, but there is no response if the request was blocked. The way I found about the extension that was blocking my resource was through the net-internals tool in Chrome: For Latest Versions of chrome Type chrome://net-export/ in the address bar and hit enter. Start Recording. And save Recording file to local. Open the page that is showing problems. Go back to net-internals You can view Recorded Log file Here https://netlog-viewer.appspot.com/#import click on events (###) and use the textfield to find the event related to your resource (use parts of the URL). Finally, click on the event and see if the info shown tells you something. For Older Versions of chro...