简体   繁体   中英

spray set content-type for XML

When trying to send an xml content-type Mime-header

sender ! HttpResponse(status = 200, entity = responseBody, headers = List(`Content-Type`(`text/xml`)))

I get the error:

not found: value text/xml

I tried with application/xml which did not work either, application/json works FWIW

Is there some import missing?

Edit: tried to add this

import spray.http.MediaTypes._
sender ! HttpResponse(status = 400, entity = responseBody, headers = List(`Content-Type`(`application/xml`)))

this gave the following error:

Explicitly set response header 'Content-Type: application/xml' is 
ignored, the response Content-Type is set via the response's HttpEntity!
import spray.http.HttpEntity    
sender ! HttpResponse(status = 200, entity = httpEntity(`application/xml`,responseBody))

relevant documentation

http://spray.io/documentation/1.2.2/spray-http/#content-type-header

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM