0
votes

I am using cakephp 2.4.5. I want to send a HTTP POST with URL parameters. I am using python 2.7 request module to send the HTTP POST. Please assume the payload is structured correctly as I have tested that part.

URL_post = http://127.0.0.1/webroot/TestFunc?identity_number=S111A/post
r = requests.post(URL_post, payload)

On the cakephp side, the controller looks something like this;

public function TestFunc($id=null)
{
    $identity_number = $this->request->query['identity_number'];  
    $this->request->data['Model']['associated_id']=$identity_number;
    $this->Model->saveAll($this->request->data, array('deep' => true));   
}

I have tested that the query is not received correctly. However, if I am not using HTTP POST and just throwing in a normal URL, the query can be received correctly.

What have I done wrong?

2
Have you checked if your value is inside $this->request->data?Roberto Maldonado

2 Answers

1
votes

The query part of the url is sent correctly:

import requests

requests.post('http://localhost/webroot/TestFunc?identity_number=S111A/post',
              {'Model': 'data'})

The Request

POST /webroot/TestFunc?identity_number=S111A/post HTTP/1.1
Host: localhost
User-Agent: python-requests/2.2.1 CPython/3.4 Linux/3.2
Accept: */*
Accept-Encoding: gzip, deflate, compress
Content-Type: application/x-www-form-urlencoded
Content-Length: 10

Model=data

You could also make the requests using params:

requests.post('http://localhost/webroot/TestFunc',
              data={'Model': 'data'},
              params={'identity_number': 'S111A/post'})

The only difference is that S111A/post is sent as S111A%2Fpost (the same url in the end).

1
votes

Look at http://docs.python-requests.org/en/latest/user/quickstart/#passing-parameters-in-urls.

payload = {"identity_number": "S111A/post"}
URL_post = "http://127.0.0.1/webroot/TestFunc"
req = requests.post(URL_post, params=payload)
print(req.status_code)