%%osspostobj.erl
-module(osspostobj).
-export([test/0]).
test()->
inets:start(),
%ssl:start(),
Method = post,
URL = "http://huabei2-ttccmj.oss-cn-beijing.aliyuncs.com",
Header = [{"User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-CN; rv:1.9.2.6)"}],
Type = "multipart/form-data; boundary=9431149156168",
Body = "--9431149156168\r\nContent-Disposition: form-data; name=\"key\"\r\n\r\n1.json\r\n--9431149156168\r\nContent-Disposition: form-data; name=\"file\"; filename=\"1.json\"\r\nContent-Type: text/plain\r\n\r\n{\"animals\":{\"key1\":2,\"key2\":\"ab\"}}\r\n--9431149156168",
BodyBin = list_to_binary(Body),
HTTPOptions = [{timeout, 30000},{connect_timeout, 5000}],
Options = [{sync, true}],
case httpc:request(Method, {URL, Header, Type, Body}, HTTPOptions, Options) of
{ok, {StatusLine,Headers,RBody}}->
io:format("receive StatusLine body:~p ~p ~p~n", [StatusLine, Headers, RBody]);
{ok, {saved_as, FilePath}}->
io:format("receive saved_as FilePath:~p~n", [FilePath]);
{ok, {Status, RBody}}->
io:format("receive Status body:~p ~p~n", [Status,RBody]);
{ok, RequestId}->
io:format("receive RequestId:~p~n", [RequestId]);
{error, Reason}->
io:format("error cause ~p~n",[Reason])
end.
出现该报错,应该是Post请求的body格式非法,正确的写法如下:
Body由一系列的表单域构成,表单域格式如下: Content-Disposition: form-data; name="{key}"rnrn{value}rn--{boundary}
具体写法可查看:https://help.aliyun.com/document_detail/31988.html
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。