(Migrated) Content-type

(This message has been automatically imported from the retired mailing list)

on command line I can issue:

curl -H “Content-type: application/json” url

I can pass the above through with python requests

headers = {‘content-type’: ‘application/json’}
r = requests.post(url, data=json.dumps(payload), headers=headers)

that seems to work. how do we add content type application/json for on out
going http connection?

is there a way to capture or log the http that is generated and sent?
verify that it’s (already?) there…

thanks

Ace

On 03/25/2014 08:15 AM, Jeffrey Gong wrote:

curl -H “Content-type: application/json” url

I can pass the above through with python requests

headers = {‘content-type’: ‘application/json’}
r = requests.post(url, data=json.dumps(payload), headers=headers)

that seems to work. how do we add content type application/json for on out
going http connection?

Hi Jeffrey,

please use the code as below:

from zato.server.service import Service

class Sample(Service):
def handle(self):

    # Obtain the handle to a connection
    conn = self.outgoing.plain_http['My Conn'].conn

    # Prepare headers for python-requests to uses
    headers = {
        'Content-Type': 'application/json',
        'X-My-Custom-Header': 'My value',
    }

    # POST a request along with headers
    conn.post(self.cid, '{"Key":"Value"}', headers=headers)

is there a way to capture or log the http that is generated and sent?

This is done by configuring logging the underlying python-requests
library to log all its activity to a selected destination.

Please have a look at your server’s ./config/repo/logging.conf file -
this is a regular Python logging configuration file that you can add
loggers to.

On 03/25/2014 08:15 AM, Jeffrey Gong wrote:

curl -H “Content-type: application/json” url

I can pass the above through with python requests

headers = {‘content-type’: ‘application/json’}
r = requests.post(url, data=json.dumps(payload), headers=headers)

that seems to work. how do we add content type application/json for on out
going http connection?

Hi Jeffrey,

please use the code as below:

from zato.server.service import Service

class Sample(Service):
def handle(self):

    # Obtain the handle to a connection
    conn = self.outgoing.plain_http['My Conn'].conn

    # Prepare headers for python-requests to uses
    headers = {
        'Content-Type': 'application/json',
        'X-My-Custom-Header': 'My value',
    }

    # POST a request along with headers
    conn.post(self.cid, '{"Key":"Value"}', headers=headers)

is there a way to capture or log the http that is generated and sent?

This is done by configuring logging the underlying python-requests
library to log all its activity to a selected destination.

Please have a look at your server’s ./config/repo/logging.conf file -
this is a regular Python logging configuration file that you can add
loggers to.

how do I get a connection outside of a service class?

what I want to do is start python interpreter interactively.

grab a connection, and run stuff trough it until I get it right.

self.outgoing.plain_http[‘My Conn’].conn

conn = OutGoingClass_plain_http() ???

thanks

On Tue, Mar 25, 2014 at 4:06 AM, Dariusz Suchojad dsuch@zato.io wrote:

On 03/25/2014 08:15 AM, Jeffrey Gong wrote:

curl -H “Content-type: application/json” url

I can pass the above through with python requests

headers = {‘content-type’: ‘application/json’}
r = requests.post(url, data=json.dumps(payload), headers=headers)

that seems to work. how do we add content type application/json for on
out
going http connection?

Hi Jeffrey,

please use the code as below:

from zato.server.service import Service

class Sample(Service):
def handle(self):

    # Obtain the handle to a connection
    conn = self.outgoing.plain_http['My Conn'].conn

    # Prepare headers for python-requests to uses
    headers = {
        'Content-Type': 'application/json',
        'X-My-Custom-Header': 'My value',
    }

    # POST a request along with headers
    conn.post(self.cid, '{"Key":"Value"}', headers=headers)

is there a way to capture or log the http that is generated and sent?

This is done by configuring logging the underlying python-requests
library to log all its activity to a selected destination.

Please have a look at your server’s ./config/repo/logging.conf file -
this is a regular Python logging configuration file that you can add
loggers to.

https://stackoverflow.com/questions/16337511/log-all-requests-from-the-python-requests-module