Questions tagged [http-request]

Use it for questions about HTTP requests, sending and receiving requests, status codes and more.

Filter by
Sorted by
Tagged with
26 votes
3 answers
18k views

How to check if the current page is a 404 error from a module/template?

How to check, in D7, if the current page is returning a 404 error from a module/template?
Andrey Rudenko's user avatar
10 votes
5 answers
7k views

error 500: Premature end of script headers: index.php

Everything works except the /node/[nr]/edit page of only one content type page. And it's not for every page of this specific content type. Only one. So let's say I have a content type "product" and ...
elterr1ble's user avatar
10 votes
1 answer
2k views

Returning alternate HTTP codes for unpublished node

I'm trying to return the 404 page instead of 403 response for unpublished nodes in Drupal 8. I tested kernel response subscriber, but found the code I was using would only change the status code to ...
oknate's user avatar
  • 14.1k
10 votes
6 answers
4k views

Friendly error page to replace WSOD

This should be the easiest thing to do, but for some reason I just can't get it done. I'm trying to get a friendly static error page to replace nasty 500 scenarios. For now I'm just trying to ...
Tommi Forsström's user avatar
6 votes
3 answers
8k views

How to get remote webpage content with drupal http request?

Would love to see some examples on getting remote webpage content with drupal http request. I have plenty of examples easily with Google with curl, but yet to find one with this drupal function. Also,...
giorgio79's user avatar
  • 4,597
5 votes
3 answers
3k views

How to issue 404 from a KernelEvents::REQUEST event

I'm trying to issue a 404 from a KernelEvents::REQUEST event, but it's resulting in the following error: Fatal error: Maximum function nesting level of '256' reached, aborting! in /var/www/vendor/...
leon.nk's user avatar
  • 386
5 votes
2 answers
18k views

How to use drupal_http_request for send data?

I need some help in sending data in an array (POST) to a webservice (REST). I need some examples in how to use the function drupal_http_request(). Now, I'm using cURL with PHP but I need to replace ...
Dvex's user avatar
  • 343
5 votes
1 answer
1k views

What should I set my Content-Security-Policy to?

I'm using Drupal 8, and I currently use Header always set Content-Security-Policy "default-src 'self'; nosniff" However, this causes bugs, such as Google Analytics not working and the textbox ...
user avatar
4 votes
1 answer
1k views

Why does drupal_http_request return a 400?

I am having issues sending a POST via my module. In my browser's REST client I get a 200 with POST https://mydomain.com username=myuser&password=password1 So I know that the service is working ...
rexposadas's user avatar
4 votes
2 answers
1k views

drupal_http_request and stream_socket_client

The D7 core function drupal_http_request uses the stream_socket_client() php function. For many serious web hosters, sockets and stream_sockets functions are a security bad practice and most of them ...
JB.'s user avatar
  • 41
3 votes
2 answers
9k views

How to show a node but return HTTP 404 response

I want to show an existing page(node) normally but return a HTTP404/410 etc instead of HTTP200. How can I do it? Is there any simple way to do it?
AgA's user avatar
  • 1,651
3 votes
5 answers
11k views

500 Internal Server Error

I changed my server and when I uploaded my site this error appeared: Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. ...
Abdulrahman's user avatar
  • 1,806
3 votes
1 answer
3k views

How to post xml data in drupal_http_request? I have curl code of it

This is following curl code $ch = curl_init(); //initiate the curl session curl_setopt($ch, CURLOPT_URL, $url); //set to url to post to curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // ...
Ali Nouman's user avatar
3 votes
1 answer
344 views

How do I return 500 for fatal errors?

When I am trying to access Drupal and the database is down, it will return a 500 error. However, when I try to access Drupal when Redis is down, it says: Additional uncaught exception thrown while ...
Quentin Skousen's user avatar
3 votes
1 answer
5k views

8 - Alter HTTP Response Headers

I noticed this question, which discusses various ways to alter HTTP Response Headers. Where would I be able to execute: $response->headers->remove('X-Frame-Options'); I attempted to place ...
Raphael Rafatpanah's user avatar
3 votes
1 answer
7k views

Guzzle httpClient Drupal Core throwing cURL error 28 Operation timed out

I have been loading the httpClient Core Service in a drupal 8 site. The service class works just fine when the request doesn't take too long from the API. It seems that if the request takes any longer ...
Hershy's user avatar
  • 181
3 votes
1 answer
570 views

drupal_http_request() returns "Invalid JSON primitive"

I am developing a module for Drupal 7 which calls a remote API. I am using drupal_http_build_query(), drupal_http_request(), and drupal_json_decode(). My code is as follows $username = $form_state['...
Richard Luckhurst's user avatar
3 votes
0 answers
328 views

Site is down due to MySQL error but it returns 200/OK

A site I help administer was showing a uncaught exception page. Additional uncaught exception thrown while handling exception. PDOException: SQLSTATE[HY000] [2002] Can't connect to local MySQL ...
Joe Corneli's user avatar
2 votes
2 answers
825 views

Hide title if 404 error

I have a custom 404 error page, and I just want a quick module that hides the 404 page title, if the user arrives at a 404 error. I've found a D7 function that looks like it would work, checking for ...
turpentyne's user avatar
2 votes
2 answers
1k views

Top level directory files like readme.txt are served by apache

The content of the top-level server directory is publicly available by the web, e.g. files like example.com/readme.txt are readable. Is it normal? How can i disable this? (apache, ubuntu 12.04)
Dalmaz's user avatar
  • 510
2 votes
1 answer
356 views

Alter Header Status Response to 410

I have several urls with "/tag/" string; some of them have content and some of them don't, so they return 404. How can I force them to return a 410 only for those that have no content? I ...
user99512's user avatar
2 votes
2 answers
892 views

Returning alternate HTTP codes for unpublished content

Sometimes when nodes are unpublished, they are not meant to be taken live again. Under those circumstances, I would like to return a 410 Gone status, instead of the default 403 Forbidden. ...
Letharion's user avatar
  • 27.5k
2 votes
1 answer
206 views

$current_user->id() returns 0 when logged in for HTTP Middleware

I have injected currentUser as a dependency into my HTTP middleware, but when I check the UID while logged in, the result is always 0. I am logged in as an admin and refreshing the watchdog page; the ...
Patrick Kenny's user avatar
2 votes
1 answer
446 views

How to add certificate to drupal_http_request()?

I am currently setting up a payment method in my Drupal 7 site and following the API documentation for the service I could use this cURL command for testing purposes: $ curl -s -S -i --cert ./...
TBJ's user avatar
  • 606
2 votes
1 answer
2k views

How do I pass parameters as JSON format to the HTTP client request?

How can I pass parameters to the http client get request in json format: $clientFactory = \Drupal::service('http_client_factory'); $client = $clientFactory->fromOptions(['verify' => FALSE]); $...
Cool's user avatar
  • 1,822
2 votes
1 answer
91 views

Need to alter response headers for error pages

We have Cloudflare sitting in front of our Drupal sites - and in order to take advantage of their "AlwaysOnline" feature - we need to alter the response code sent in the event of an error. I want to ...
Wayne Foster's user avatar
2 votes
2 answers
1k views

Non-blocking HTTP request with Guzzle

Is there a Drupal 8 way to do non-blocking HTTP client request using Guzzle? I don't need to wait for the answer of The HTTP post, as that is slowing down the site. I already seen Non-blocking ...
lchabrand's user avatar
  • 364
2 votes
1 answer
422 views

Can I use the session service directly instead of via the request?

The Drupal documentation on sessions mentions that sessions can be accessed via the Request object: Session data is accessed via the \Symfony\Component\HttpFoundation\Request::getSession() method, ...
Neograph734's user avatar
  • 8,379
2 votes
0 answers
61 views

How can I access nested data?

Im currently using Drupal's http client manager module to pull data from a json endpoint. I am having trouble getting this to work for a nested structure like this. { count: 2431 page_info: [] ...
tnum's user avatar
  • 21
2 votes
0 answers
232 views

How do I access data nested within JSON in a Guzzle service description response model? [closed]

I'm trying to pull some data into Drupal from a service, via Guzzle. I've got several clients like this working, but the data returned by this service is structured a bit differently: { pager: [ ], ...
WRD's user avatar
  • 187
2 votes
0 answers
93 views

Getting An AJAX http error occured when updating modules

I recently staring getting a "An AJAX HTTP error occurred. HTTP Result Code: 500 Debugging information follows. Path: http://192.168.1.20/alan_page/authorize.php?batch=1&id=67&op=do ...
Alan's user avatar
  • 121
2 votes
1 answer
1k views

Font Awesome not working when using HTTP

We have 2 subdomains for a website in order to test our development before moving to production. This is our structure: subdomainA.mysite.com subdomainB.mysite.com mysite.com When I enter to ...
Alex Vargas's user avatar
2 votes
1 answer
2k views

AJAX returns response code 200, and displays error messages in callbacks

I'm running Drupal 7.34 with quite a few modules (relevant because unfortunately I did not notice when the problem first started and it would take ages to look through them all one by one) and I have ...
Andy's user avatar
  • 775
1 vote
2 answers
379 views

Making an HTTP subrequest causes CurrentRouteMatch to have the wrong route

For complicated and unpleasant reasons[*], I want to embed entity data from the JSONAPI module inside JSON returned from a REST module resource. I am trying to do this by making an HTTP subrequest to ...
joachim's user avatar
  • 846
1 vote
1 answer
605 views

Handling access denied result

In Drupal 8, what is the correct way of returning access denied to a user (outside of access requirement on a controller)? I'd say it is to throw an AccessDeniedHttpException most of the time, but I ...
Kevin's user avatar
  • 27.7k
1 vote
1 answer
10k views

How do I send a drupal_http_request() with GET method?

Following examples found here and in API, I tried 2 methods, both return a bad request status message. First method $data = 'name=value&name1=value1'; $options = array( 'method' => 'GET', ...
Kojo's user avatar
  • 3,523
1 vote
1 answer
103 views

Sub request doesn't take care of the language

I have defined a route as follow: mymodule.node_summary: path: '/node/{node}/summary' options: parameters: node: type: 'entity:node' defaults: _controller: '\Drupal\...
Baud's user avatar
  • 570
1 vote
1 answer
684 views

How to handle the cache per user in REST Resource?

I have a requirement to expose a specific content type data via REST end point. Below is my code: public function get() { $current_user = $this->currentUser->id(); $user = $this->...
Suraj's user avatar
  • 884
1 vote
1 answer
863 views

How to get the uncached version of request headers?

We need to programmatically get the request headers using the mymodule_preprocess_page hook. To do this we tried the following, however, because we have CDN, Varnish, and Drupal Cache all enabled, the ...
usernameabc's user avatar
  • 2,676
1 vote
1 answer
360 views

How do I get request parameters when using fragment AND query with drupal_goto

I was successful in using fragment with drupal_goto, but when I use it AND query, I am not able to get the request parameters using $_GET from the query. I can see the request parameters in the URL,...
angms.bh's user avatar
  • 535
1 vote
1 answer
287 views

Jquery Ajax to Drupal to External site, reading response

I have a drupal site. There is a page (page 1) with a form that gathers user info and submits it via AJAX to a Drupal Module page. The AJAX format is jquery var responseTarget = '/site/module/...
Niccolo's user avatar
  • 143
1 vote
2 answers
407 views

WSOD while sending headers, probably Cache-related

I have a very strange problem with a fresh Drupal install: On some pages, I receive a WSOD with ERR_EMPTY_RESPONSE: It happens for instance when on admin/config/development/performance I click Clear ...
Georg Jähnig's user avatar
1 vote
1 answer
2k views

Drupal::httpClient() and proxy settings

I've defined a proxy in my settings.php: $settings['http_client_config']['proxy']['http'] = 'http://ip:port'; $settings['http_client_config']['proxy']['https'] = 'http://ip:port'; $settings['...
AndyLicht's user avatar
1 vote
1 answer
1k views

Page redirect based on referrer

I am looking for an option to redirect user referred from a specific url (say abc.com) to domain.com/abc in Drupal 7 if http_referrer='abc.com' redirect to xyz.com/abc I looked at Redirect, http ...
Sandeep's user avatar
  • 11
1 vote
2 answers
837 views

drupal_http_request times out on Google Maps geocoding URL

When I navigate to http://maps.google.com/maps/api/geocode/json?address=1200+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false (the Google Maps Geocoding API test address) in my browser (Chrome)...
beth's user avatar
  • 9,087
1 vote
1 answer
1k views

404 page not found error even though the page exists

On my Drupal 7 website, I'm getting a 404 page not found error on the front page: http://mydomain.com even though I can view the page just fine. Google Webmaster tools wouldn't validate my site; w3 ...
Tom Stermitz's user avatar
1 vote
1 answer
581 views

Troubleshooting a Drupal HTTP 500 when there are no error log messages

I have reviewed some websites on how to troubleshoot HTTP 500 on a Drupal site and most often I have seen a PHP error by running drush ws in the console, however, I have been running into an oddity ...
Mark L's user avatar
  • 13
1 vote
0 answers
92 views

Custom module routing issue

I've a custom module where I have create the following route: my.custom.route: path: /{someVariable}/my-module/test defaults: _controller: '\Drupal\my_module\Controller\...
Paulo's user avatar
  • 11
1 vote
1 answer
201 views

Use async with drupal_http_request()

I need to make an asynchronous call with drupal_http_request(). Is it possible?
user106028's user avatar
1 vote
1 answer
162 views

Convert Acquia Clear Varnish For One URL Curl Command to Drupal::httpClient()

I am trying to convert a command to php curl or Drupal::httpClient(). The original command Curl -k -X PURGE -H "X-Acquia-Purge:[site-name]" --compressed -H "Host: example.com" ...
Alaa Haddad's user avatar