Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
HttpResponse post
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  10 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Mike  
View profile  
 More options Feb 16 2009, 10:37 am
From: Mike <migue...@gmail.com>
Date: Mon, 16 Feb 2009 07:37:51 -0800 (PST)
Local: Mon, Feb 16 2009 10:37 am
Subject: HttpResponse post
Hi all,

I m not familiar with django and I have found several problems trying
to sent a httpresponse with post parameters. I would like to return an
httpresponse (or httpredirect) to a new url with the request
parameters via post.

Could anybody help me?
Thank you in advance,
Miguel

I have defined a new view:

def prueba(request, seccion):
 if request.POST:
        new_data = request.POST.copy()

[get all the parameters]
[send a mail if correct]

        response = HttpResponse ("newUrl")
        #żPOST?
    return HttpResponseRedirect(response)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Antoni Aloy  
View profile  
 More options Feb 16 2009, 11:18 am
From: Antoni Aloy <antoni.a...@gmail.com>
Date: Mon, 16 Feb 2009 17:18:08 +0100
Local: Mon, Feb 16 2009 11:18 am
Subject: Re: HttpResponse post
2009/2/16 Mike <migue...@gmail.com>:

After a post you should use a HttpResponseRedirect(url). If you need
to have access to the post parameters an option is to save them in a
session, or encode them in the url itslef.

Hope it helps!

--
Antoni Aloy López
Blog: http://trespams.com
Site: http://apsl.net


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Miguel  
View profile  
 More options Feb 17 2009, 3:04 am
From: Miguel <migue...@gmail.com>
Date: Tue, 17 Feb 2009 09:04:44 +0100
Local: Tues, Feb 17 2009 3:04 am
Subject: Re: HttpResponse post

The problem is that I need to redirect the request to an url and post to
this url the parameters I got from the initial request and display the post
url. Here is my views.py:

def prueba(request, seccion):

    if request.POST:
        new_data = request.POST.copy()

        Ds_Merchant_Titular = new_data['Ds_Merchant_Titular']
        Ds_Merchant_MerchantCode = new_data['Ds_Merchant_MerchantCode']
        Ds_Merchant_Amount = new_data['Ds_Merchant_Amount']
        Ds_Merchant_Currency = new_data['Ds_Merchant_Currency']
        Ds_Merchant_Order = new_data['Ds_Merchant_Order']

        correo_from = Ds_Merchant_Titular
        correo_asunto = "[contacto] " + Ds_Merchant_MerchantCode
        correo_to = []

       correo_to.append(MIEMAIL)
        correo_content = Ds_Merchant_Order

        sendMail(correo_to, correo_asunto, correo_content, True,
correo_from)
        params = urllib.urlencode({"Ds_Merchant_Titular":
Ds_Merchant_Titular, "Ds_Merchant_MerchantCode": Ds_Merchant_MerchantCode})
        #f= urllib2.urlopen("https://sis.sermepa.es/sis/realizarPago
",params)

   return f  -> it doesnt workd

   # return HttpResponseRedirect("https://sis.sermepa.es/sis/realizarPago",params)
--> it doesn't work


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Karen Tracey  
View profile  
 More options Feb 17 2009, 10:15 am
From: Karen Tracey <kmtra...@gmail.com>
Date: Tue, 17 Feb 2009 10:15:21 -0500
Local: Tues, Feb 17 2009 10:15 am
Subject: Re: HttpResponse post

On Tue, Feb 17, 2009 at 3:04 AM, Miguel <migue...@gmail.com> wrote:
> [snip]
>         params = urllib.urlencode({"Ds_Merchant_Titular":
> Ds_Merchant_Titular, "Ds_Merchant_MerchantCode": Ds_Merchant_MerchantCode})
>         #f= urllib2.urlopen("https://sis.sermepa.es/sis/realizarPago
> ",params)

>    return f  -> it doesnt workd

>    # return HttpResponseRedirect("https://sis.sermepa.es/sis/realizarPago",params)
> --> it doesn't work

No, it wouldn't.  HttpResponseRedirect is documented (
http://docs.djangoproject.com/en/dev/ref/request-response/#django.htt...)
to take a single argument.  You can yourself combine params and location
into the url argument to HttpResponseRedirect:

return HttpResponseRedirect("?".join(("
https://sis.sermepa.es/sis/realizarPago",params)))

but that won't force the client browser to use a POST when retrieving the
redirect location.  The redirect response contains a status code and
location, there is no field for the server to specify what method should be
used to access the specified location.  Standards actually specify that the
browser must use the same method as was used on the original request (which
seems to be what you want), but that is not, in fact, what most browsers
do.  See:

http://en.wikipedia.org/wiki/HTTP_302

Karen


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Miguel  
View profile  
 More options Feb 17 2009, 12:52 pm
From: Miguel <migue...@gmail.com>
Date: Tue, 17 Feb 2009 18:52:01 +0100
Local: Tues, Feb 17 2009 12:52 pm
Subject: Re: HttpResponse post

thanks karen, that is what I meant.
So there is no way to return in my views.py an external web html with post
parameters ... it must be a way to do that, dont think so?

Karen, if I try your example
return HttpResponseRedirect("?".join(("
https://sis.sermepa.es/sis/realizarPago",params))), the web site is not
shown in the web browser I can see the url of my django place but not
https://sis.sermepa.es/sis/realizarPago.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Antoni Aloy  
View profile  
 More options Feb 17 2009, 1:28 pm
From: Antoni Aloy <antoni.a...@gmail.com>
Date: Tue, 17 Feb 2009 19:28:10 +0100
Local: Tues, Feb 17 2009 1:28 pm
Subject: Re: HttpResponse post
2009/2/17 Miguel <migue...@gmail.com>:
> thanks karen, that is what I meant.
> So there is no way to return in my views.py an external web html with post
> parameters ... it must be a way to do that, dont think so?

Yes, but you can't do it this way.

Just check for httplib and httplib2.

http://code.activestate.com/recipes/146306/

or from Python documentation in http://docs.python.org/library/httplib.html

>>> import httplib, urllib
>>> params = urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0})
>>> headers = {"Content-type": "application/x-www-form-urlencoded",

...            "Accept": "text/plain"}

>>> conn = httplib.HTTPConnection("musi-cal.mojam.com:80")
>>> conn.request("POST", "/cgi-bin/query", params, headers)
>>> response = conn.getresponse()
>>> print response.status, response.reason
200 OK
>>> data = response.read()
>>> conn.close()

Hope it helps!

--
Antoni Aloy López
Blog: http://trespams.com
Site: http://apsl.net


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Miguel  
View profile  
 More options Feb 18 2009, 9:07 am
From: Miguel <migue...@gmail.com>
Date: Wed, 18 Feb 2009 15:07:07 +0100
Local: Wed, Feb 18 2009 9:07 am
Subject: Re: HttpResponse post

well, I am not a python programmer and maybe I am doing silly things or this
is not as complex as I see but I not able to do what you mention above.
 I get the error,
'NoneType' object has no attribute 'read'

I have tried to follow http://code.activestate.com/recipes/146306/, with
only fields (the fields of my form) but I get stack here  return
h.file.read()  with the mentioned error.

I have also tried httplib.HTTPS but there is no way to get the results  I
wanted.
(i have also commeted  errcode, errmsg, header = ..., because i got some
errors)
here is my code:

    fields = [('Ds_Merchant_Titular', Ds_Merchant_Titular),( .........
]

    content_type, body = encode_multipart_formdata(fields)
    h = httplib.HTTPS("sis.sermepa.es",443)
    h.putrequest('POST', '/sis/realizarPago')
    h.putheader('content-type', content_type)
    h.putheader('content-length', str(len(body)))
    h.endheaders()
    h.send(body)
    #errcode, errmsg, headers = h.getreply()
    return h.file.read()

I have also tried with this code:

         ......
        data = urlencode(request.POST)
        resp, content = conn.request(u"
https://sis.sermepa.es/sis/realizarPago", 'POST', data)
        sys.stderr.write("\n\n\n\n mikimiki ----- " + content);
    return HttpResponse(content)

But here I get the URL of my django place in my browser instead of
https://sis.sermepa.es/sis/realizarPago. I mean, all the images and
resources are refered to relative paths and I not able to display the page.
For sure    return HttpResponse(content) is not the way as Antoni commented.

could anybody clarify me anything?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Devin  
View profile  
 More options Feb 20 2009, 10:39 pm
From: Devin <venable.de...@gmail.com>
Date: Fri, 20 Feb 2009 19:39:03 -0800 (PST)
Local: Fri, Feb 20 2009 10:39 pm
Subject: Re: HttpResponse post
I have no problem pulling pages using httplib if the pages do not
require authentication.  But now I want to pull pages only after
authenticating.  Access is enforced by the contributed auth package.

import httplib, urllib
params = urllib.urlencode({'this_is_the_login_form':1,'username':
'myuser', 'password': 'test'})
headers = {"Content-type": "application/x-www-form-urlencoded",
            "Accept": "text/plain"}
conn = httplib.HTTPConnection("myserver")
conn.request("POST", "/login/", params, headers)
response = conn.getresponse()
print response.status, response.reason

As I said, when hitting pages that do not require auth, I am
successful and get a 200 response code.  But when auth is needed, I
get 302 for the code and "found" for the status.

Any insights?

On Feb 17, 12:28 pm, Antoni Aloy <antoni.a...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Malcolm Tredinnick  
View profile  
 More options Feb 20 2009, 10:58 pm
From: Malcolm Tredinnick <malc...@pointy-stick.com>
Date: Sat, 21 Feb 2009 14:58:08 +1100
Local: Fri, Feb 20 2009 10:58 pm
Subject: Re: HttpResponse post

So you need to act like a browser would. Submit the necessary
authentication form variables, save the returned cookie and send it on
subsequent requests.

Not sure how this is related ot the original question in the thread,
though, which was about redirecting what the user's browser retrieves,
not retrieving web pages inside Python scripts.

Regards,
Malcolm


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
hoamon  
View profile  
 More options Mar 4 2009, 5:11 am
From: hoamon <hoa...@gmail.com>
Date: Wed, 4 Mar 2009 02:11:03 -0800 (PST)
Local: Wed, Mar 4 2009 5:11 am
Subject: Re: HttpResponse post
Hi all,

I write a experimental example to reach this requirement.  By AJAX
method, we can make a post type form after server answer.

my example is below here:

http://hoamon.blogspot.com/2009/03/return-httpresponseredirect-by-pos...


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »