Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Content-type set to "text/plain; charset=UTF-8" for POST #87

Closed
vbauer opened this issue Nov 16, 2012 · 13 comments
Closed

Content-type set to "text/plain; charset=UTF-8" for POST #87

vbauer opened this issue Nov 16, 2012 · 13 comments

Comments

@vbauer
Copy link

vbauer commented Nov 16, 2012

When POSTing to a REST API, the Content-Type is set to "text/plain; charset=UTF-8", not to "application/json".

@vbauer
Copy link
Author

vbauer commented Nov 16, 2012

Request Headers:

Accept  application/json, text/javascript, */*; q=0.01
Accept-Encoding gzip, deflate
Accept-Language en-US,en;q=0.5
Connection  keep-alive
Content-Length  74
Content-Type    text/plain; charset=UTF-8
Cookie  __utma=111872281.121724330.1352468000.1352468000.1352468000.1; __utmz=111872281.1352468000.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); rememberMe=dS+4thm9Y23BpwpthcFWR4oV3+LRaH+RAR3m9sr6gNVaOfpKDALkgmkL6KDps81L7aeSHawXGj8GWUlcMc1OcrrEPemKTaN7Rze/KpySJp54QvtBQHQh+yQFSwRsrvDLCCPv9UCxy6M9mwQqc/rxyJiRijRhit1D52f4S5wUywIUpAUxYKEdSWgW9QpzFZLeL0qDplegHi3ysYeEUGrE6oNYszFPr+cghiV1DkGv/35lRp9hdfZLC7zjf3GssXfz4uypX0XLG1IeIUwGl+zK+AqNNfd5Uanil2vXXS1461mGzS4bWu4td2O6/lSdGhZREmGybRRDGnvEqhFC+o1FU2P0t7BPgRy7MSnO/13F4aETP0YyFwh+bqsHE9oj4CFy7I2AuXmtIeg1kpFiSk7dsXS/xKR+VO9azJuGLVpj64xo8jMe5xJb5qCultEW3kbuyWqEjgDEMgn25Xrtrjl9cPAbT7mQvP95MJjSsBcaokaMOL7qDdoRECLWbh+zKpIPGpt+BS+qaaSOPYlfW+O/IjiTSwNRccbFXb9vVOObUkM=; Ticket="time#Sat Nov 17 00:57:27 NOVT 2012&hash#E9YPAGbTCYwxmIPdXFpydA==&salt#-1981530176-2&operator_id#5&akio_lang#en/us"; JSESSIONID=CA68A43757C4BD1B37A6E86F63A9CCB0
Host    localhost:8080
Referer http://localhost:8080/restapi/
User-Agent  Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:16.0) Gecko/20100101 Firefox/16.0
X-Requested-With    XMLHttpRequest

Checked with Firefox 16.0.2.

@SvenBunge
Copy link

Checked with Google Chrome and Swagger UI 1.1.3 & 1.1.4: It sends 'application/xml' as content-type - so doesn't work with REST-Endpoints only accept application/json!

Accept:application/json, text/javascript, */*; q=0.01
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4
Connection:keep-alive
Content-Length:165
Content-Type:application/xml

With Swagger UI 1.1.2 it is also not working. "Content-Type:application/x-www-form-urlencoded; charset=UTF-8" is set for the response header.

Workaround: Add a manual request header in the index.html

supportHeaderParams: true,
headers: { "Content-Type": "application/json; charset=UTF-8" },

@vbauer
Copy link
Author

vbauer commented Nov 22, 2012

Hmm.. I checked on last snapshot and it doesn't work. But!
Workaround works perfect! Thank you very much!!

@lradziwonowicz
Copy link

I think the lines (1515-1517) in swagger-ui.js (1.1.5) are responsible for this bug:

if (isFileUpload) {
     obj.contentType = false;
}

Source: OperationView.coffee Line: 126

obj.contentType = false if isFileUpload

@facultymatt
Copy link

Im getting this same bug in Chrome, applications/xml

@steveturner
Copy link

Experiencing this too: isFileUpload = $('input[type~="file"]').size != 0 does not seem to work properly in Chrome 23.0.1271.91

@fehguy
Copy link
Contributor

fehguy commented Nov 30, 2012

I think a couple different issues are being described here.

@vbauer @facultymatt you're saying that POST is not setting the right content type? Can you please confirm you have POST enabled, as described here: https://github.com/wordnik/swagger-ui#http-methods-and-api-invocation

@lradziwonowicz is this check only affecting file uploads?

@fehguy
Copy link
Contributor

fehguy commented Dec 5, 2012

addressed the default content-type in version 1.1.7, please reopen if you still see issues.

@fehguy fehguy closed this as completed Dec 5, 2012
@chrisware
Copy link

Still seems to be present in 1.1.7.

Calling size() as a method fixes the problem:

isFileUpload = $('input[type~="file"]').size() !== 0;

@fehguy
Copy link
Contributor

fehguy commented Mar 28, 2013

Hi @chrisware, I just updated the README--it was pointing to downloads in github, which have been deprecated. The latest version is in the dist folder of the repo. Please try with that, and it should work as-is.

@mayorbyrne
Copy link

@fehguy to avoid confusion, you might want to push those dist folder changes across the board. I'm not sure where more old files are hiding, but I had a horrible time with POST requests using the serverless version (https://github.com/wordnik/swagger-core/tree/master/samples/no-server) until i stumbled across this issue and updated the files with the ones in the dist folder.

@kamil-kielczewski
Copy link

I use this

  • consumes={"multipart/form-data"},
    
  • produces={"text/plain, application/json"}, 
    

@ashwath20
Copy link

ashwath20 commented Apr 22, 2020

Have you changed the mode is set to no-cors then it changes the Content-type then Content-type filed become immutable
in case you are using node js (express) server

var cors = require('cors')
app.use(cors())
``` then request from local host will go through
and do not use `mode` in  request header

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants