strange behavior with PostData - Set Cookie Header in Oracle Server

Hello!
First of all, thanks for this lib! 
Sorry for my english.

well, I already solve this, but I just want to make the report about an issue I found.

I am trying to make a simple login to a website (with all the headers, with session, etc)

Server where i am trying to send the request is an Oracle XML DB/Oracle Database Oracle-Web-Cache-11g/11.1.1.6.0

I use httpliveheader to see the log networking, I use all the headers!
Example : 
s = requests.Session()
headers = { 'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:38.0) Gecko/20100101 Firefox/38.0',
            'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,_/_;q=0.8',
            'Accept-Language': 'es-CL,es;q=0.8,en-US;q=0.5,en;q=0.3',
            'Accept-Encoding': 'gzip, deflate',
            'Referer': 'http://domain:9090/apex/f?p=102:1',
            'Content-Type': 'application/x-www-form-urlencoded',
        }

data =  {   "data":"1",
            "data":"2",
        }
r1 = s.post('http://www.domain.com:9090/apex/wwv_flow.accept',data=data,allow_redirects=False,headers=headers)
print r1.headers
print(r1.status_code, r1.reason)

I use allow_redirects to see the set-cookie. that is all I want.

but for some reason, this is not working. honestly I dont know why, I dont see the header set-cookie, and the system say, the user and pass are incorrect, and that is wrong, because I can login in firefox with that credentials.

So  I use sockets and works.

import socket   #for sockets
import sys  #for exit
# create an INET, STREAMing socket

try:
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except socket.error:
    print 'Failed to create socket'
    sys.exit()
print 'Socket Created'

host = 'domain.com';
port = 9090;

try:
    remote_ip = socket.gethostbyname( host )
except socket.gaierror:
    #could not resolve
    print 'Hostname could not be resolved. Exiting'
    sys.exit()
# Connect to remote server

s.connect((remote_ip , port))
print 'Socket Connected to ' + host + ' on ip ' + remote_ip
# Send some data to remote server

message  = 'POST /apex/wwv_flow.accept HTTP/1.1\r\n'
message += 'Host: domain:9090\r\n'
message += 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:38.0) Gecko/20100101 Firefox/38.0\r\n'
message += 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,_/_;q=0.8\r\n'
message += 'Accept-Language: es-CL,es;q=0.8,en-US;q=0.5,en;q=0.3\r\n'
message += 'Accept-Encoding: gzip, deflate\r\n'
message += 'Referer: http://domain.com/9090/apex/f?p=102:1\r\n'
message += 'Connection: keep-alive\r\n'
message += 'Content-Type: application/x-www-form-urlencoded\r\n'
message += 'Content-Length: LEN\r\n\r\n'
message += 'DATA'

try :
    #Set the whole string
    s.sendall(message)
except socket.error:
    #Send failed
    print 'Send failed'
    sys.exit()
print 'Message send successfully'
# Now receive data

reply = s.recv(4096)
print reply

and now I receive the header with set-cookie.
maybe this could help to another person.

Regards.


can you use tcpdump or a similar tool to compare the headers generated by requests and your code?


Hey @Lukasa !

I use this command. (http://justniffer.sourceforge.net/)
sudo justniffer -i eth0 -r > log_socket.txt

Here is the log related with request:
http://paste2.org/mhZCj2t7

and here is the log related with socket.

http://paste2.org/8ztZbD7K

what I see is, socket make two request. and requests just make one.

the important value for me is:
Set-Cookie: LOGIN_USERNAME_COOKIE=<ID_USERNAME>
Set-Cookie: WWV_CUSTOM-F_1279122985171442_102=8DA9C805E89B5CAE; path=/

because with that value I create another requests to get the content in the system.

I hope this help!

And thanks Lukasa!


PD: 
this value in the requests log

Location: f?p=102:101:4311424845483966&notification_msg=Credenciales%20de%20conexi%C3%B3n%20no%20v%C3%A1lidas/FBB8C9F8A0FFD40A59B8FBFE55E8E065/

is related with the failure, because I will be redirected to the login page with the message "invalid connection" (but in spanish - Conexion invalida)

and in the postdata is the same for each request (using requests and sockets)


Are you sure the postdata is the same for both requests? Because requests is setting the content-length to 189, but your socket code sets it to 218.

Out of interest, do you have some non-ASCII characters in your body?


Closing due to inactivity.