From: brad smith Date: 2013-06-13T22:39:39+09:00 Subject: Re: post request of digest auth --001a11c2675ccad08304df09306b Content-Type: text/plain; charset=ISO-8859-1 I am unsure what `www_auth_response` is suppose to do. Also you have `return` at the end of the `post_data` method which is probably not what you want. What does the server side request look like when you call this post method? On Tue, Jun 11, 2013 at 3:58 AM, Kirill Grin wrote: > m fighting with post request of digest auth a few days and still can't > get how to send json body. Please help me! Server told that i got in, > but by json was not used. i'm using net/http/digest_auth gem. Is i think > json must be placed in the right place, but I don't now where. Thanks a > lot! > > def post_data > uri = URI.parse 'http://somelink.com' > uri.user = 'test' > uri.password = 'test' > > data = {:ID => "123456789", :name => "me"} > data_type = JSON.generate(data) > > digest_auth = Net::HTTP::DigestAuth.new > > h = Net::HTTP.new uri.host, uri.port > h.set_debug_output $stderr > > req = Net::HTTP::Post.new uri.request_uri > res = h.request req > > www_auth_response = res['www-authenticate'] > www_auth_response["algorithm=\"MD5\""] = "algorithm=MD5" > auth = digest_auth.auth_header uri, www_auth_response, 'POST' > > req = Net::HTTP::Post.new uri.request_uri > req.add_field 'Authorization', auth > req.content_type= "application/json" > req.body = data_type > > res = h.request req > puts res.code > return > end > > -- > Posted via http://www.ruby-forum.com/. > > --001a11c2675ccad08304df09306b Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
I am unsure what `www_auth_response` is suppose to do.=A0<= div>Also you have `return` at the end of the `post_data` method which is pr= obably not what you want.
What does the server side request look = like when you call this post method?


O= n Tue, Jun 11, 2013 at 3:58 AM, Kirill Grin <lists@ruby-forum.com= > wrote:
m fighting with post request of digest auth = a few days and still can't
get how to send json body. Please help me! Server told that i got in,
but by json was not used. i'm using net/http/digest_auth gem. Is i thin= k
json must be placed in the right place, but I don't now where. Thanks a=
lot!

def post_data
=A0 uri =3D URI.parse 'http://somelink.com'
=A0 uri.user =3D 'test'
=A0 uri.password =3D 'test'

=A0 data =3D {:ID =3D> "123456789", :name =3D> "me&quo= t;}
=A0 data_type =3D JSON.generate(data)

=A0 digest_auth =3D Net::HTTP::DigestAuth.new

=A0 h =3D Net::HTTP.new uri.host, uri.port
=A0 h.set_debug_output $stderr

=A0 req =3D Net::HTTP::Post.new uri.request_uri
=A0 res =3D h.request req

=A0 www_auth_response =3D res['www-authenticate']
=A0 www_auth_response["algorithm=3D\"MD5\""] =3D "= algorithm=3DMD5"
=A0 auth =3D digest_auth.auth_header uri, www_auth_response, 'POST'=

=A0 req =3D Net::HTTP::Post.new uri.request_uri
=A0 req.add_field 'Authorization', auth
=A0 req.content_type=3D "application/json"
=A0 req.body =3D data_type

=A0 res =3D h.request req
=A0 puts res.code
=A0 return
end

--
Posted via http://= www.ruby-forum.com/.


--001a11c2675ccad08304df09306b--