Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7446171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T12:14:33+00:00 2026-05-29T12:14:33+00:00

I want to send chunked HTTP body to test my own HTTP server. So

  • 0

I want to send chunked HTTP body to test my own HTTP server.
So I wrote this python code:

import http.client

body = 'Hello World!' * 80

conn = http.client.HTTPConnection("some.domain.com")
url = "/some_path?arg=true_arg"

conn.request("POST", url, body, {"Transfer-Encoding":"chunked"})

resp = conn.getresponse()
print(resp.status, resp.reason)

I expect the HTTP request’s body is transferrd chunked,
but I capture the network package with Wireshark, the HTTP request’s body is not transferred chunked.

How to transfer chunked body by http.client lib in python?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T12:14:37+00:00Added an answer on May 29, 2026 at 12:14 pm

    OK, I get it.

    First, write my own chunked encode function.

    Then use putrequest(), putheader(), endheaders() and send() instead of request()

    import http.client
    
    def chunk_data(data, chunk_size):
        dl = len(data)
        ret = ""
        for i in range(dl // chunk_size):
            ret += "%s\r\n" % (hex(chunk_size)[2:])
            ret += "%s\r\n\r\n" % (data[i * chunk_size : (i + 1) * chunk_size])
    
        if len(data) % chunk_size != 0:
            ret += "%s\r\n" % (hex(len(data) % chunk_size)[2:])
            ret += "%s\r\n" % (data[-(len(data) % chunk_size):])
    
        ret += "0\r\n\r\n"
        return ret
    
    
    conn = http.client.HTTPConnection(host)
    url = "/some_path"
    conn.putrequest('POST', url)
    conn.putheader('Transfer-Encoding', 'chunked')
    conn.endheaders()
    conn.send(chunk_data(body, size_per_chunk).encode('utf-8'))
    
    resp = conn.getresponse()
    print(resp.status, resp.reason)
    conn.close()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to send a UIImage to a server with socket. I'm using this
I want to send this URL as a request to the server to change
What is the correct way for a HTTP server to send data over multiple
I want to send a couple of values to a web server from my
I want to send a message to userID=3 by going to /MyController/Message/3 This executes
How can i send meta info to client, for example. i have this method
I have some action. I want send mail. usually i doing this way. public
I want to send out one off emails from a linux server. The server
I want to send the data of a UIImage to the server through a
I want to send 410 status code if there is any ? on the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.