English 中文(简体)
Yaws and PUT requests
原标题:
  • 时间:2010-10-14 13:25:06
  •  标签:
  • rest
  • yaws

I just started working with Yaws to try to create some simple RESTful web services, however I ran into an unexpected issue: I can t seem to access my data when I do a PUT request. When I try to use the yaws_api:parse_post function, I get the following error:

ERROR: Can t parse post body for  PUT  requests: URL: ...

I wrote out the entire request and everything looks identical, so I m very confused. Am I doing something wrong? GETs and POSTs work properly. In fact, the only difference between how I handle POSTs and PUTs right now is just what I display for each as right now I m just writing test code to show success.

Thanks in advance.

最佳回答

I also find it weird that there s no equivalent of parse_post/1 for non-POST HTTP methods in the Yaws API.

In any case, I simply use parse_query/1 for PUTs. Given a PUT request with param1=abc, param2=def:

index(Args) ->
  case yaws_arg:method(Args) of
   PUT  ->
    Parsed = yaws_api:parse_query(Args),
    io:format("PUT PARAMS=~p", [Parsed]),
    ....
   POST  ->
    ....

the output is:

PUT PARAMS=[{"param1","abc"}, {"param2","def"}}]

(The above example is in a Erlyweb controller.)

问题回答

You should add (or change) the parameter "dav = true" in the file "yaws.conf" into the section <server> like this:

<server ...>
        dav = true
</server>

The data for PUT is located in #arg.clidata, like it is for a POST. Internally the call to parse_query and parse_post ultimately use the same function to parse GET and POST.

A work around for PUT parameters in the body is therefore

Parsed = yaws_api:parse_query( Arg#arg{ querydata = Arg#arg.clidata } ),

It works by copying the clidata field (data in the body) to the querydata field and parsing it like a GET.

This assumes that the body is urlencoded like for a POST.





相关问题
Comparison among NIO webservers [closed]

We need to put in our architecture a server for streaming contents to (potentially) millions of phones. Here the architects and operations people know only about Java, but I d really to propose ...

yaws and erlang beam files in ebin

I am having problems when i have integers and float numbers in my form posts and receive these in my ebin file where i have beam files. Hope someone can help me. npower.yaws <erl> kv(K,L) -...

How to set up yaws-1.89 in ubuntu?

I need help with setting up yaws-1.89 in ubuntu. This is the error I get: =INFO REPORT==== 3-Dec-2010::16:52:40 === Yaws: Using config file /home/hudson2010/yaws.conf =ERROR REPORT==== 3-Dec-2010::...

Yaws and PUT requests

I just started working with Yaws to try to create some simple RESTful web services, however I ran into an unexpected issue: I can t seem to access my data when I do a PUT request. When I try to use ...

Erlang s maximum number of simultaneous open ports?

Does the erlang TCP/IP library have some limitations? I ve done some searching but can t find any definitive answers. I have set the ERL_MAX_PORTS environment variable to 12000 and configured Yaws to ...

How do I disable debug checks in yaws?

When i start yaws (yaws -i --conf config/yaws.conf) i get this line in the output: Running with debug checks turned on (slower server) It depends on the "-i" option? Or where did i turned on debug ...

Mochiweb : Reading a file as it is uploaded

I want to be able to read a file just as it is being uploaded by the user, i.e. I want to read the incoming stream of bytes from the user s browser.. Is that possible with Mochiweb? If not, where do I ...

热门标签