TIP: Use Markdown or, <pre> for multi line code blocks / <code> for inline code.
Forums are in read-only mode while we transition to new software.
Set content-type for external PUT request?
  • Hello Kohana Community!

    Duplicate of: http://stackoverflow.com/questions/5252996/kohana-request-set-content-type

    I am having difficulty setting the content-type header of an external Kohana3.1+ request.

    $r = Request::factory($this->api) ->method(Request::PUT) ->body($this->to_json()) ->headers('content-type', 'application/json');

    The request ends up being executed by curl. The CURLOPT_ settings for the request type (PUT) and the request body (the json) are set correctly, but the content type does not get set.

    Am I going about this in the wrong way?

    I have debugged all the way down to Kohana_Request_Client_External class and at run time the $options variable in that class definitely gets the PUT and JSON, and it has a 3rd entry, but the value of that entry is the number 1.

    Any help much appreciated!

    Thanks, Finbarr

  • Did you try calling send_headers() with your request? Also I doubt it matters, but it might be better practice to upper case Content-Type header.

  • Which class has the send_headers() method?

  • If I'm not mistaken you can just chain it on to your request like: $r = Request::factory($this->api) ->method(Request::PUT) ->body($this->to_json()) ->headers('content-type', 'application/json')->send_headers();

  • Sending headers is done by the response, not the request. The request will automatically send headers when calling execute() for external requests.

  • Well it seems that the content-type header does not get sent.

  • $response = Request::factory($this->api)
        ->method(Request::PUT)
        ->headers('content-type', 'application/json')
        ->body($this->to_json())
        ->execute();
    

    Does the above not work for you @Finbarr?

  • Somebody created this issue today...

  • @Darsstar I cherrypicked the fix attached to that issue and my problem is resolved.

Howdy, Stranger!

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

In this Discussion