Change Content-Type and WebKitFormBoundary

7,931 views
Skip to first unread message

Sam Ben Yakar

unread,
Jul 25, 2013, 11:09:03 AM7/25/13
to swagger-sw...@googlegroups.com
  1. Every time that i create post or put request from swagger-ui
  2. The header has
  3. Content-Type:
    multipart/form-data; boundary=----WebKitFormBoundarywba9BBWF69AaPg2g
and the Request params has:
  1. ------WebKitFormBoundarywba9BBWF69AaPg2g Content-Disposition: form-data; name="token"

How can i cancel it ?

tony tam

unread,
Jul 25, 2013, 11:20:43 AM7/25/13
to swagger-sw...@googlegroups.com
Hi, what version of swagger-ui?  I'm guessing your POST or PUT has form values in it, which is why it's setting the content type as multipart/form-data.  What does your operation look like?  If you share the json, it'd be helpful

Sam Ben Yakar

unread,
Jul 25, 2013, 11:33:25 AM7/25/13
to swagger-sw...@googlegroups.com
Hi tony,
i'm using 1.1.15, yes they are form params

{
  "basePath": "http:\/\/example.com\/wsv2\/user",
  "swaggerVersion": "1.1",
  "apiVersion": "0.1",
  "resourcePath": "\/wsModel",
  "apis": [
    {
      "path": "\/Facebook",
      "operations": [
        {
          "httpMethod": "POST",
          "summary": "User Token",
          "nickname": "token",
          "responseClass": "AcceptnResponse",
          "parameters": [
            {
              "name": "token",
              "description": "User Token",
              "allowMultiple": false,
              "dataType": "string",
              "paramType": "form",
              "required": true
            }
          ],
          "errorResponses": [
            {
              "reason": "Bad token",
              "code": 403
            }
          ]
        }
      ],
      "description": "Facebook Callback"
    },

tony tam

unread,
Jul 25, 2013, 11:43:13 AM7/25/13
to swagger-sw...@googlegroups.com
Hi, that's what is expected.  The type FORM means swagger will send the data as a FORM post, and defaults to multipart/form-post as content type.  If you want to send values in an HTTP post, you can send them as either a json object, or as header/query/path parameters.  Make sense?

Sam Ben Yakar

unread,
Jul 25, 2013, 11:51:43 AM7/25/13
to swagger-sw...@googlegroups.com
Make sense,
But when is send it as a json i can't see it in me server, Using PHP. The $_REQUEST doesn't contain it

tony tam

unread,
Jul 25, 2013, 12:09:15 PM7/25/13
to swagger-sw...@googlegroups.com
You should create an object to send, such as `UserToken` and change the param type from `form` to `UserToken`.  Then swagger will let you post json like such:

{
  "token" : "abc123"
}

Your php server should consume this fine.

Sam Ben Yakar

unread,
Jul 25, 2013, 12:22:26 PM7/25/13
to swagger-sw...@googlegroups.com
Not Working,


When i change paramType to "UserToken" i get a warning 
[WARN] Unexpected paramType "UserToken", expecting "path", "query", "body", "header" or "form" 

when i make it with body and dataType="UserToken"
I can send the data but still can't see it at the server

tony tam

unread,
Jul 25, 2013, 12:28:58 PM7/25/13
to swagger-sw...@googlegroups.com
My apologies, I mistyped it.  What you did is correct, paramType = `body` and dataType = `UserToken`.  I suggest you try with curl to see that it's not a server issue.

curl -X POST -d '{"userToken":"abc123"}' -H "Content-Type:application/json" http://....

Sam Ben Yakar

unread,
Jul 25, 2013, 12:39:16 PM7/25/13
to swagger-sw...@googlegroups.com
My framework didn't support restful API
i added 
file_get_contents("php://input");
and then i can see the data.

Thanks 

tony tam

unread,
Jul 25, 2013, 12:47:54 PM7/25/13
to swagger-sw...@googlegroups.com
Ok, so you have things working now?

Sam Ben Yakar

unread,
Jul 25, 2013, 12:48:43 PM7/25/13
to swagger-sw...@googlegroups.com
Yes, Thanks!

tony tam

unread,
Jul 25, 2013, 1:03:09 PM7/25/13
to swagger-sw...@googlegroups.com
ok great
Reply all
Reply to author
Forward
0 new messages