Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
can not access to custom header variable
  • i cant access to json post variables and header variable:
    sample :
    variable: a=1
    header variable = b=2

    access from php :(done)
    other: file_get_contents('php://input');
    header : $SERVER['HTTP_B']

    access from fuelphp :(error)
    DomainException [ Error ]:Don't know how to parse input of type: text/plain
    COREPATH/classes/input/instance.php @ line 513

    you can test with rest client extension in firefox or chrome

  • How about Input::json()?

    You can read php://input only once (up until PHP 5.6, after that depending on implementation), and the Framework reads and processes it when it starts.
  • hi Harro
    Input::json() return error
    DomainException [ Error ]:Don't know how to parse input of type: text/plain
    COREPATH/classes/input/instance.php @ line 513
    and i cant access to header variable
  • logical, json data should be of type application/json?

    You have to set the correct content type on your ajax call.
  • is not ajax call, its android request in json post format (standard) and i can access to all of variable in php but not in fuelphp

    i write sample in my first post,
    it is fuelphp error and not php or other thing

  • HarroHarro
    Accepted Answer
    Because in your plain PHP example you simply ignore the content type, you assume that whatever is input is in application/json format, and process it as such.

    Fuel can't do that. As the input can be in different formats (Fuel supports all obious ones), you need to know what it is before you can parse it. It is therefore not a FuelPHP error, it is the android app that fails to set the correct Content-Type, which is required as per the HTTP standard.

    Don't work around a problem, fix it. 

  • thanks harro,
    in fuelphp there is no define for text/plain Content-Type that is my problem.
    you can test with rest client extension in firefox or advanced rest client in chrome browser for see what happend.

    please see
    core/classes/input/instance.php => hydrate() function (error line in question)

    $content type is : application/x-www-form-urlencoded, multipart/form-data, application/json, application/xml, text/xml
    and not have text/plain

  • No, because text/plain is no data content type. 

    How would you parse that data? Nothing says that is contains json. or multiform/data. or a posted image. or...

    We're not going to hardcode anything weird just because you happen to have a non-compliant client. Fix the client. Don't work around the problem.
  • I'm having the same problem.

    I am trying to setup a webhook that allows a service not controlled by me to call into my service. When the service calls me it sets Content-Type to be "application/soap+xml". This isn't covered by the platform right now and throws an exception:

    Any suggestions on how to handle this? It's a pretty large service, probably something that should be covered by fuel.

    I'm thinking maybe the solution is to split by + and evaluate both as application/(type) then check if contained in the list of types?
  • It should simply ignore it I think.

    Input of type "application/soap+xml" should be parsed by the application, you can't expect Input to know every form of posted input. SOAP especially is in a class of it's own, certainly if it contains security related features, for which you need a decent SOAP library.

    I'll change the "throw" to a log call. In the meantime, just comment out that line.
  • Sounds like a good plan. What do you think the best way to parse this data is then? Since it will come in unparsed, just read it in with Format::forge?
  • If it is really SOAP, and not some simple XML, you need a SOAP library to work with it. PHP has an internal SOAPclient that works fine for the basics, but requires a lot of coding to work with it.

    Internally we use a customized version of, converted into a package with an oil wrapper, which will use the SOAP WSDL file to generate PHP classes based on the entities and relations defined. It allows you to interact with the SOAP service in an OOP way.

    Check for more info.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion