RESTful-Drupal / restful

RESTful best practices for Drupal
https://drupal.org/project/restful
419 stars 173 forks source link

can't post data for article #930

Open thlo7777 opened 8 years ago

thlo7777 commented 8 years ago

Hi, Guys I want to create an article from mobile to drupal, but restful return:

{ "type": "http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.1", "title": "No values were sent with the request", "status": 400, "detail": "Bad Request", "instance": "http://dld.dreamland360.com/help/restful/problem-instances-bad-request" }

my restful api is http://dld.dreamland360.com/api/my_articles

post data:

{ "data": { "type": "article", "attributes": { "title": "restful test create node", "body": "hello my first restful" } }

}

my class is

`/**

namespace Drupal\dld_restful_api\Plugin\resource\node\article\v1;

use Drupal\restful\Plugin\resource\ResourceInterface; use Drupal\restful\Plugin\resource\ResourceNode;

/**

and my drupal log show me

Notice: Undefined property: stdClass::$nid 在 entity_metadata_no_hook_node_access() (行 682 在 /home/www/dld/sites/all/modules/entity/modules/callbacks.inc).

Anyone can give me some clues, thank a lot

thlo7777 commented 8 years ago

I found when I post the data to server, postman fill Content-Type: application/json, and I saw it from apache log. But restful parseBody function always get empty content type from getHeaders(), then it will set "application/x-www-form-urlencoded" for content type. I thought might be varnish cause I use apache + varnish + drupal. But it still exists after I disabled varnish

Has anyone can help me to explain it? Many thanks

thlo7777 commented 8 years ago

wrote a log in restful() function in restful.module. Every time manager increase size when received a http request from client. Because manager object has exists, it will not invoke createFromGlobals to check http header again, so can't get Content-Type: application/json. May be something was wrong to invoke parse Content-Type: application/json for old http request.

I compared manager object size after received multiple http requests using same json api, the manager size keep every request result and the object size is increasing. Does anyone know how to clear manger cache or reduce it correctly. Otherwise if server get tens of thousands of requests, how big size about manager?

thlo7777 commented 8 years ago

found apache_request_headers() return value can't get content-type and content length in Request.php

I use apache 2.4.7 + php-fpm module. May be apache_request_headers can't work for php-fpm

e0ipso commented 8 years ago

@thlo7777 unfortunately I don't have an environment like that. Would you be able to submit a pull request?

thlo7777 commented 8 years ago

OK, I'll try to explain it as detail as possible